美文网首页
nginx配置一个端口反向代理多个项目

nginx配置一个端口反向代理多个项目

作者: 缪先生_ | 来源:发表于2020-03-16 15:43 被阅读0次

    参考链接: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; 
            }
            # 部署在同台服务器的后端地址,跨域请求
            location /bpi {
                # rewrite实现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)$ {
            #     #禁止缓存,每次都从服务器请求
            #     add_header Cache-Control no-store;
            # }
            # ^~ 开头表示uri以某个常规字符串开头,不是正则匹配
            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;
            }    
        }
    

    相关文章

      网友评论

          本文标题:nginx配置一个端口反向代理多个项目

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