美文网首页
nginx 配置备忘录

nginx 配置备忘录

作者: Dr丶net | 来源:发表于2019-07-08 14:57 被阅读0次
#user  nobody;
worker_processes  1;
error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
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;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    gzip  on;
    gzip_static on; 
   
    upstream server_api{
        # api 代理服务地址
        server 127.0.0.1:3330;    
    }
    #关闭ip直接访问资源
    server {
       listen 80 default;
       server_name _;
       return 403;
    }    
    server {
        listen   80;
        server_name www.drnet.xyz drnet.xyz;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
                proxy_pass http://127.0.0.1:3330;
        root html;
        index index.html;
        }
    location /api {
       proxy_pass http://server_api/users;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_cookie_path /users/ /;
            proxy_set_header Cookie $http_cookie;
    }
    }
    server {
        listen       80;
        server_name manager.drnet.xyz huangfujiankang.top;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        location / {
            try_files $uri $uri/ /index.html;
            root   html/manager;
            index  index.html index.htm;
        }
        # 匹配 api 路由的反向代理到API服务
        location /api {
            proxy_pass http://server_api/users;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_cookie_path /users/ /;
            proxy_set_header Cookie $http_cookie;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

相关文章

网友评论

      本文标题:nginx 配置备忘录

      本文链接:https://www.haomeiwen.com/subject/xxnohctx.html