Nginx

Nginx:位置正則表達式不起作用

  • April 7, 2015

我的正則表達式遇到問題不知道它有什麼問題。它返回一個 URiorls/f而不是orls/f?p=4550. 當我經過https://secure.toto02.com/orls/myservice/f?p=4550

我的conf文件在下面

location ~ "^/([a-zA-Z]+)/myservice/(.+)$" {

   error_log  /var/log/nginx/error-server.log notice;
   rewrite_log on;  

   #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-Forwarded-Proto $scheme;


   proxy_pass http://192.168.3.45:8080/orls/$2;    
   proxy_redirect http://192.168.3.45:8080/orls/ https://secure.toto02.com/$1/myservice/ ;          
}   

任何人都可以幫忙嗎?

擷取位置不會包含查詢字元串。您必須通過$is_args$args變數手動包含它,如下所示:

proxy_pass http://192.168.3.45:8080/orls/$2$is_args$args;

請參閱@kolbyjack(更好)的答案:https ://stackoverflow.com/questions/8130692/with-nginx-how-to-forward-query-parameters

引用自:https://serverfault.com/questions/681043