nginx配置一個端口反向代理多個項目

參考鏈接:https://blog.csdn.net/lorogy/article/details/104413315/
nginx.conf 文件

http {
    include       mime.types;
    default_type  application/octet-stream;
    add_header X-Cache-Status $upstream_cache_status;
    sendfile        off;
    keepalive_timeout  65;

    # 項目1
    server {
        listen       8081;
        server_name  192.168.1.88;
        location / {
            try_files $uri $uri/ /index.html;
            root   D:/xxx;
            index  index.html index.htm; 
        }
        # 部署在同臺服務(wù)器的后端地址,跨域請求
        location /bpi {
            # rewrite實現(xiàn)url重寫以及重定向,去掉api,http://XX:8086/index
            rewrite ^.+api/?(.*)$ /$1 break;
            #include uwsgi_params;
            proxy_pass http://XX:8086; 
        }
        #第三方接口,跨域請求,需要改打包的配置文件(如vue的打包配置)
        # location /api/ {            
        #     proxy_pass http://www.scis.net.cn/literature/; 
        # }
    }
    server {
        listen       8082;
        server_name  192.168.1.88;
        location / {
            try_files $uri $uri/ /index.html;
            root   D:/xxx;
            index  index.html index.htm; 
        }
    }
    server {
        listen       80;
        server_name  192.168.1.88;

        # location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {
        #     #禁止緩存,每次都從服務(wù)器請求
        #     add_header Cache-Control no-store;
        # }
        # ^~ 開頭表示uri以某個常規(guī)字符串開頭,不是正則匹配
        location ^~/mhapp/ {
          add_header Cache-Control no-cache;
          add_header Cache-Control private;
          expires -1s;
          proxy_redirect off;
          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_pass http://192.168.1.88:8081/;
        }
        location ^~/web/ {
          add_header Cache-Control no-cache;
          add_header Cache-Control private;
          expires -1s;
          proxy_redirect off;
          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_pass http://192.168.1.88:8082/;
        }

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

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }    
    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容