nginx 踩坑之旅

一个 nginx.conf 的 demo 配置:

#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;
    client_max_body_size 10m;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /xxx_screen{
                if ($request_filename ~* .*\.(?:htm|html)$){
                        add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
                }
                root /data/service/xxx_service/front;
                try_files $uri $uri/  /xxx_screen/index.html;
                index index.html;
        }

        location ^~ /xxxApi/ {
                proxy_pass   http://127.0.0.1:8080/;
        }

        location ^~ /api/ {
                #  include  uwsgi_params;
                proxy_pass   http://127.0.0.1:8888/;

                # 以下4行可以解决通过 nginx 来进行后台的 websocket 连接失败的问题
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_read_timeout 86400;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    server {
        listen       8080;
        server_name  localhost;

        location / {
            #root   html;
            #index  index.html index.htm;

            # 以下1行配置可以解决 “例如第一次请求 http://xxx.xxx.xxx.xxx:8080/xxx 而跳转到 nginx 欢迎界面,需要再次请求 http://xxx.xxx.xxx.xxx:8080/xxx 才能进入/xxx页面” 的问题
            return 301 http://xxx.xxx.xxx.xxx:8080/xxx;
        }
    }
}

你可能感兴趣的:(linux,nginx,nginx,运维,linux,tomcat,java,springboot)