Nginx配置使用详解

配置步骤:

1、配置nginx的方法:首先要打开“/etc/nginx/conf.d/”文件夹;

2、然后创建配置文件;接着在“/etc/nginx/nginx.conf”文件中修改配置项;

3、最后重新启动nginx即可

Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器
Nginx (engine x) 也是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的 (推荐学习:nginx教程

前后端nginx配置

1.打开 /etc/nginx/conf.d/文件夹,创建配置文件xxx.conf,内容如下:

    server {
    listen 80;
    server_name **.106.2**.175;
    location / {
            root   /public/app/dist;
            index  index.php index.html index.htm;
    }

    location /sell {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   Host      $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass         http://127.0.0.1:8080;
        proxy_redirect off;

    }}

2.在 /etc/nginx/nginx.conf文件中有一行就是把刚刚配置的引进总的nginx配置中

...

    include /etc/nginx/conf.d/*.conf;...

3.配置完成后重新启动nginx

nginx -t                         # 查看nginx状态
nginx -s reload            # 重新载入配置文件
nginx -s reopen           # 重启 Nginx
nginx -s stop               # 停止 Nginx

4.配置https

server {
        listen 443;
        server_name xx.name.com;
        ssl on;
        index index.html index.htm;
        ssl_certificate   cert/215079423330181.cert;
        ssl_certificate_key  cert/215079423330181.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        location / {
           root   /public/app/dist;
           index  index.php index.html index.htm;
        }

        location /sell {
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   Host      $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass         http://127.0.0.1:8080;
            proxy_redirect off;
        }
   }

5.nginx.conf 默认文件

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;

worker_processes auto;

error_log /var/log/nginx/error.log;

pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    gzip on;
    gzip_static on;
    gzip_min_length 1024;
    gzip_buffers 4 16k;
    gzip_comp_level 2;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript   application/x-httpd-php application/vnd.ms-fontobject font/ttf font/opentype font/x-woff image/svg+xml;
    gzip_vary off;
    gzip_disable "MSIE [1-6]\.";

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

    server {
         listen 443;
         server_name mp.hanxing.store;
         ssl on;
         index index.html index.htm;
         ssl_certificate   cert/cert_mp.hanxing.store.crt;
         ssl_certificate_key  cert/cert_mp.hanxing.store.key;
         ssl_session_timeout 5m;
         ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
         ssl_prefer_server_ciphers on;

         location / {
            root   /public/sell/app/dist;
            index  index.php index.html index.htm;
         }

         location /sell {
             proxy_set_header   X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header   Host      $http_host;
             proxy_set_header X-NginX-Proxy true;
             proxy_pass         http://127.0.0.1:8080;
             proxy_redirect off;
         }

         error_page 404 /404.html;
              location = /40x.html {
         }

         error_page 500 502 503 504 /50x.html;
            location = /50x.html {
         }
    }
}

以上就是nginx怎么配置的详细内容!

到此这篇关于Nginx配置使用的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • windows系统安装配置nginx环境

    一. nginx软件拷贝 拷贝 nginx文件 到对应的服务目录中 如 E:/service/nginxnginx文件地址: 链接: https://www.jb51.net/softs/25646.html 二. 在项目盘中创建wwwroot 及 wwwconf 在日常开发的盘中添加 wwwroot 目录 (用于放置站点文件 ) 并添加 wwwconf 目录 (用于放置 nginx站点配置) 三 .修改nginx配置文件 找到 E:/service/nginx/conf 目录下的 nginx.

  • nginx常用配置conf的示例代码详解

    nginx常用配置conf 代理静态文件 # 静态文件 server { # 压缩问价你配置 gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 6; gzip_types text/plain text/css application/javascript application/json image/jpeg image/png image/gif; gzip_disa

  • Nginx配置文件详解以及优化建议指南

    目录 1.概述 2.nginx.conf 1)配置文件位置 2)worker_processes 3)events 4)include 5)sendfile 和 tcp_nopush 6)keepalive_timeout 7)gzip 8)server 9)location的匹配规则详解 3.综述 1.概述 今天来详解一下Nginx的配置文件,以及给出一些配置建议,希望能对大家有所帮助. 2.nginx.conf 1)配置文件位置 nginx 安装目录的 conf 文件夹下,例如:/usr/l

  • nginx安装以及配置的详细过程记录

    目录 1 nginx 介绍 1 什么是nginx 2 应用场景 2 nginx安装 1 下载 2 安装要求的环境 1.需要安装gcc环境 2.第三方的开发包 3 nginx安装过程 3 启动nginx 4 查看nginx是否启动 5 关闭nginx 6 重启nginx 7 刷新配置文件 8 关闭防火墙,开启远程访问 9 访问nginx 10 配置虚拟主机 11 通过端口区分不同的主机 12 多个域名区分虚拟主机 1 什么是域名 2 nginx配置 3 测试 13 正向代理 14 反向代理 15

  • nginx容器配置文件独立的实现

    创建一个容器 [root@server1 ~]# docker run -it --name nginx1 -v /opt/data/web2:/web -p 81:80 centos:latest /bin/bash [root@608de4875036 /]# 进入web目录,下载nginx包 [root@608de4875036 web]# wget http://nginx.org/download/nginx-1.20.1.tar.gz 解压目录 [root@608de4875036

  • Nginx安装配置详解

    不论是本地开发,还是远程到 Server 开发,还是给提供 demo 给人看效果,我们时常需要对 Nginx 做配置,Nginx 的配置项相当多,如果考虑性能配置起来会比较麻烦.不过,我们往往只是需要一个静态 Server,或者一个反向代理 Server,这对 Nginx 来说小菜一碟. 简介 Nginx 的安装: # CentOS yum install nginx; # Ubuntu sudo apt-get install nginx; # Mac brew install nginx;

  • Nginx的一些常用配置汇总

    目录 Nginx配置文件结构 Nginx日志切割 root 与 alias 使用GZIP压缩提升请求效率 location匹配规则解析 使用SwitchHosts模拟本地域名解析 Nginx跨域配置支持 Nginx防盗链支持 Nginx负载均衡 upstream指令参数 Keepalived 提高吞吐量 Nginx的缓存 Nginx的反向代理缓存 使用Nginx配置HTTPS域名证书 总结 Nginx配置文件结构 1.设置worker进程的用户,指的linux中的用户,会涉及到nginx操作目录

  • Nginx配置使用详解

    配置步骤: 1.配置nginx的方法:首先要打开“/etc/nginx/conf.d/”文件夹: 2.然后创建配置文件:接着在“/etc/nginx/nginx.conf”文件中修改配置项: 3.最后重新启动nginx即可 Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器Nginx (engine x) 也是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务.Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler

  • 强大的Nginx配置生成器详解

    目录 构建镜像 安装 端口 命令行安装 运行 参考文档 本文折腾于 9 月中旬: 老苏虽然用过很多次 nginx ,但是对 nginx 并不熟悉,基本上是每次要用的时候才会去搜索解决方案,所以一直在找一个配置工具,Nginx Config 虽然不能完全满足老苏的需求,但也可以作为参考之用. 什么是 Nginx Config ? Nginx Config 是一款可以一键生成 Nginx 配置的神器,相当给力.支持反向代理.HTTPS.HTTP/2.IPv6, 缓存.WordPress.CDN.No

  • Nginx配置优化详解

    大多数的Nginx安装指南告诉你如下基础知识--通过apt-get安装,修改这里或那里的几行配置,好了,你已经有了一个Web服务器了!而且,在大多数情况下,一个常规安装的nginx对你的网站来说已经能很好地工作了.然而,如果你真的想挤压出nginx的性能,你必须更深入一些.在本指南中,我将解释Nginx的那些设置可以微调,以优化处理大量客户端时的性能.需要注意一点,这不是一个全面的微调指南.这是一个简单的预览--那些可以通过微调来提高性能设置的概述.你的情况可能不同. 基本的(优化过的)配置 我

  • ThinkPHP 在阿里云上的nginx.config配置实例详解

    具体代码如下所示: # For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log;

  • Nginx 多站点配置实例详解

    Nginx 多站点配置实例详解 在一台 VPS 上,我们有时候需要同时跑几个 virtualenv.比如 virtualenv app1 跑的是 Django 的一个应用,而 virtualenv app2 跑的是 Tornado.那么如何配置 Nginx,让它同时支持这两个 virtualenv 的运行呢? 首先是 Nginx 的主配置,位于 etc/nginx/ngnix.conf,让它保持默认就行: user nginx; worker_processes 1; error_log /va

  • Centos7下nginx的安装与配置教程详解

    说明:软件安装的基础目录路径:/usr/local 所以下载软件的时候切换到此目录下下载直接解压即可 1.安装gcc gcc-c++依赖包 yum install -y gcc gcc-c++ 2.下载编译安装PCRE库 切换到usr/local目录下执行命令 下载安装包 wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz 解压安装包 tar -zxvf pcre-8.36.tar.gz 编译安

  • Nginx+Tomcat负载均衡集群安装配置案例详解

    目录 前言 一.Nginx+Tomcat 二.配置Nginx服务器 三.部署Tomcat应用服务器 总结 前言 介绍Tomcat及Nginx+Tomcat负载均衡集群,Tomcat的应用场景,然后重点介绍Tomcat的安装配置.Nginx+Tomcat负载均衡集案列是应用于生产环境的一套可靠的Web站点解决方案. 一.Nginx+Tomcat 通常情况下,一个Tomcat站点由于可能出现单点故障及无法应付过多客户复杂多样的请求等问题,不能单独应用于生产环境下,所以我们需要一套更可靠的解决方案来完

  • 关于Nginx动静分离详解以及配置

    1.Nginx动静分离概念 动静分离,通过中间件将动态请求和静态请求进行分离,分离资源,减少不必要的请求消耗,减少请求延时. 好处:动静分离后,即使动态服务不可用,但静态资源不会受到影响 通过中间件可以将动态请求和静态请求进行分离 2.Nginx动静分离应用案例 2.1.环境规划 系统 服务 服务 地址 centos7.5 负载均衡 Nginx proxy 192.168.81.210 centos7.5 静态资源 Nginx static 192.168.81.220 centos7.5 动态

  • Apache和Nginx的优缺点详解_动力节点Java学院整理

    Apache和Nginx比较 功能对比 Nginx和Apache一样,都是HTTP服务器软件,在功能实现上都采用模块化结构设计,都支持通用的语言接口,如PHP.Perl.Python等,同时还支持正向和反向代理.虚拟主机.URL重写.压缩传输.SSL加密传输等. 在功能实现上,Apache的所有模块都支持动.静态编译,而Nginx模块都是静态编译的, 对FastCGI的支持,Apache对Fcgi的支持不好,而Nginx对Fcgi的支持非常好: 在处理连接方式上,Nginx支持epoll,而Ap

  • Nginx服务器Nginx.com配置文件详解

    在此记录下Nginx服务器nginx.conf的配置文件说明, 部分注释收集与网络. #运行用户 user www-data; #启动进程,通常设置成和cpu的数量相等 worker_processes 1; #全局错误日志及PID文件 error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; #工作模式及连接数上限 events { use epoll; #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但

随机推荐