nginx添加location跳轉后不生效


需求:匹配api借口跳轉到指定url

nginx配置如下:

upstream sp-api {
        server sp-api:80 max_fails=3 fail_timeout=3;
}
server {
        server_name sp-test.
.com;
        root /usr/local/src/dist/;
        client_max_body_size 50M;
        add_header Access-Control-Allow-Origin '*';
        proxy_buffer_size  128k;
        proxy_buffers   32 32k;
        fastcgi_buffers 32 32k;
        fastcgi_buffer_size 128k;
        proxy_temp_file_write_size 128k;
        proxy_busy_buffers_size   256k;
        access_log /var/log/nginx/sp_access.log;
        error_log /var/log/nginx/sp_error.log;
        proxy_set_header host $host;
      location / {
        autoindex on;
        index index.html;
        try_files $uri /index.html;
      }
      location /msm-api {                         # 這里是新加的location
        proxy_pass https://msm-test.erp.chicv.com/;
      }
      location /sp-api/ {.                          
         proxy_pass http://sp-api/;
      }
      location ~.*\.(htm|html)$ {
       add_header Cache-Control no-store;
       add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
      }

}
上訴配置更新后,發現location沒有跳轉,具體原因是因為 proxy_set_header host $host; 參數導致,刪除后即恢復正常,如果使用該參數建議放到具體的模塊中使用


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM