nginx 配置记录

81 阅读1分钟

nginx.conf :

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

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

/etc/nginx/conf.d/server.conf :


server {
    listen       8080;
    server_name  localhost;
    root   /app/lib/fed/dist/;
    index  index.html;
    client_max_body_size 200M;                    #上传文件大小限制
    sendfile        on;
    resolver xx.xxx.x.xxx; # 动态域名解析地址

    if ($http_host ~* "fed.(.*).tc.test.com") { # 动态配置服务器域名
       set $pure_host fed-backend.$1.tc.test.com;
    }

    # set $env ops;
    # 探针
    location /info {
        add_header Content-Type 'text/json; charset=utf-8';
        return 200 '{"status": "ok"}';
    }

    location / {
        add_header Cache-Control 'no-cache, must-revalidate, proxy-revalidate, max-age=0';
        try_files $uri $uri/ $uri/index.html /_prerender/index.html /index.html;
    }

    location /staticFront/ {
        rewrite ^/staticFront/(.*)$ /$1 break;
        expires max;
    }

    location /static/ { # 管理端静态服务器
         proxy_pass http://$pure_host;
         proxy_read_timeout 600s;
    }

    location /api/v1/ {
        proxy_pass http://$pure_host;
        proxy_read_timeout 600s;
    }
    location /api/v2/ {
        proxy_pass http://$pure_host;
        proxy_read_timeout 600s;
    }
}