美文网首页
Nginx反向代理去除前缀

Nginx反向代理去除前缀

作者: yellow_han | 来源:发表于2020-03-05 20:54 被阅读0次
方法一:
server {
    listen       80;
    server_name  v.bensoo.com;
    client_max_body_size 100m;

    location ^~/wxapp/ {
        proxy_set_header Host $host;
        proxy_pass http://web_server/;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        root  /usr/local/tomcat/webapps/ROOT;
        index index.html index.htm;
    }
    location / {
                root /etc/nginx/html/bensoo-video-sys;
                index  home.html index.html index.htm;
                chunked_transfer_encoding on;
                add_header Cache-Control no-cache;
    }

    error_page  500 502 503 504 /50x.html;
    location = /50x.html {
        root  /etc/nginx/html;
    }
}
方法二:rewrite
server {
    listen       80;
    server_name  v.bensoo.com;
    client_max_body_size 100m;

    location ^~/wxapp/ {
        proxy_set_header Host $host;
        proxy_pass http://web_server/;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        root  /usr/local/tomcat/webapps/ROOT;
        index index.html index.htm;
    }
    location / {
                root /etc/nginx/html/bensoo-video-sys;
                index  home.html index.html index.htm;
                chunked_transfer_encoding on;
                add_header Cache-Control no-cache;
    }

    error_page  500 502 503 504 /50x.html;
    location = /50x.html {
        root  /etc/nginx/html;
    }
}
server {
    listen              80;
    server_name  abc.com;
    access_log  "pipe:rollback /data/log/nginx/access.log interval=1d baknum=7 maxsize=1G"  main;

    location ^~/user/ {
        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_set_header X-NginX-Proxy true;

        rewrite ^/user/(.*)$ /$1 break;
        proxy_pass http://user;
    }

    location ^~/order/ {
        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_set_header X-NginX-Proxy true;

        rewrite ^/order/(.*)$ /$1 break;
        proxy_pass http://order;
    }
}

相关文章

网友评论

      本文标题:Nginx反向代理去除前缀

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