nginx.conf - nginx配置文件模板

前往https://www.jianshu.com/p/fbb967b0670a直接复制代码


#4核8g机器的nginx代理配置

#vim /usr/local/nginx/conf/nginx.conf

user  nginx;

#没有出现io性能问题,采用默认的1即可;非要设置,必须要和CPU的内核数8匹配

#worker_processes  1;

#worker_rlimit_nofile 102400;

error_log  /data0/log/nginx/error.log  notice;

pid        /data0/log/nginx/nginx.pid;

#配置影响nginx服务器或与用户的网络连接

events {

    use epoll;

    worker_connections  65535;

}

http {

    include mime.types;

    default_type application/octet-stream;

    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 logs/access.log main;

    #client_max_body_size 50m;

    #client_body_buffer_size 256k;

    #client_header_timeout 120s;

    #client_body_timeout 120s;

    #send_timeout 1m;

    sendfile on;

    #tcp_nopush on;

    #keepalive_timeout 0;

    keepalive_timeout 65;

    #gZip配置

    #gzip on;

    #gzip_http_version 1.1;

    #gzip_comp_level 5;

    #gzip_min_length 1000;

    #gzip_types gzip_types text/csv text/xml text/css text/plain text/javascript application/javascript application/x-javascript application/json application/xml;

    #负载均衡服务器列表

    upstream data-server {

        server 127.0.0.1:8080;

    }

    upstream static-web-server {

        server 127.0.0.1:8888;

    }

    server {

        listen 666;

        server_name localhost;

        #charset koi8-r;

        #access_log logs/host.access.log main;

        # 在Server级别配置反向代理的参数

        proxy_redirect off ;

        proxy_set_header Host $host;

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header REMOTE-HOST $remote_addr;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # 第一个必选规则

        # 直接匹配网站根,起始页码跳转到index.html,通过域名访问网站首页比较频繁,使用这个会加速处理

        # 这里是一个静态首页,也可以直接转发给后端应用服务器

        location = / {

            rewrite /index.html last;

            #proxy_pass http://static-web-server/index;

        }

        # 第二个必选规则是处理静态文件请求,这是nginx作为http服务器的强项

        # 有两种配置模式,目录匹配或后缀匹配,任选其一或搭配使用

        location ^~ /static/ {

            #proxy_set_header Host $host:8888; # 根据需要

            #proxy_pass http://static-web-server;

            root /root/static/;

        }

        #location ~* \.(gif|jpg|jpeg|png|css|js|ico)$ {

        #    root /root/res/;

        #}

        # 第三个必选规则

        # 默认反向代理到通用规则

        location / {

            # proxy_set_header Host $host:8888; # 根据需要

            proxy_pass http://static-web-server;

        }

        # 特殊页面 1

        location ~* (login|logout).html$ {

            # proxy_set_header Host $host:666; # 根据需要

            proxy_pass http://data-server;

        }

        # 特殊页面 2

        location ~* openid {

            # proxy_set_header Host $host:666; # 根据需要

            proxy_pass http://data-server;

        }

        # 通用数据接口以do或者json结尾的,反向代理到数据服务器

        location ~* .(do|json)$ {

            # proxy_set_header Host $host:666; # 根据需要

            proxy_pass http://data-server;

        }

        # 数据接口服务器

        location ~* (login|logout)$ {

            #proxy_set_header Host $host:666; # 根据需要

            proxy_pass http://data-server;

        }

    }

}

你可能感兴趣的:(nginx.conf - nginx配置文件模板)