国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > Nginx > 正文

詳解proxy_pass根據path路徑轉發時的"/"問題記錄

2024-08-30 12:24:49
字體:
來源:轉載
供稿:網友

在nginx中配置proxy_pass時,如果是按照^~匹配路徑時,要注意proxy_pass后的url最后的/。當加上了/,相當于是絕對根路徑,則nginx不會把location中匹配的路徑部分代理走;如果沒有/,則會把匹配的路徑部分也給代理走。

比如下面設置:

location ^~ /wangshibo/{proxy_cache js_cache;proxy_set_header Host js.test.com;proxy_pass http://js.test.com/;}

如上面的配置,如果請求的url是http://servername/wangshibo/test.html會被代理成http://js.test.com/test.html

而如果這么配置

location ^~ /wangshibo/{proxy_cache js_cache;proxy_set_header Host js.test.com;proxy_pass http://js.test.com;}

則請求的url是http://servername/wangshibo/test.html會被代理到http://js.test.com/wangshibo/test.html

當然,可以用如下的rewrite來實現/的功能

location ^~ /wangshibo/{proxy_cache js_cache;proxy_set_header Host js.test.com;rewrite /wangshibo/(.+)$ /$1 break;proxy_pass http://js.test.com;}

列舉下面一例

1)第一種配置

[root@BJLX_16_202_V vhosts]# cat ssl-wangshibo.confupstream at {  server 192.168.1.202:8080 max_fails=3 fail_timeout=30s;}  server {  listen 443;  server_name www.wangshibo.com;  ssl on;    ### SSL log files ###  access_log logs/wangshibo_access.log;  error_log logs/wangshibo_error.log;  ### SSL cert files ###  ssl_certificate ssl/wang.cer;    ssl_certificate_key ssl/wang.key;    location /attendance/ {  proxy_pass http://at;                             //不需要加上"/"            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;  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 https;  proxy_redirect off;    }  }

訪問https://www.wangshibo.com/attendance/和http://192.168.1.202:8080/attendance結果是一致的。

2)第二種配置

[root@BJLX_16_202_V vhosts]# cat ssl-wangshibo.confupstream at {  server 192.168.1.202:8080 max_fails=3 fail_timeout=30s;}  server {  listen 443;  server_name www.wangshibo.com;  ssl on;    ### SSL log files ###  access_log logs/wangshibo_access.log;  error_log logs/wangshibo_error.log;  ### SSL cert files ###  ssl_certificate ssl/wang.cer;    ssl_certificate_key ssl/wang.key;    location / {  proxy_pass http://at/attendance/;                         //一定要加上"/"              proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;  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 https;  proxy_redirect off;    }  }

訪問https://www.wangshibo.com和http://192.168.1.202:8080/attendance結果是一致的。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 尼勒克县| 茶陵县| 嘉峪关市| 林芝县| 耒阳市| 渝北区| 会昌县| 平邑县| 会同县| 泽州县| 开平市| 盐边县| 中西区| 册亨县| 凉山| 清苑县| 昔阳县| 贺兰县| 尼木县| 广州市| 台东县| 彝良县| 北流市| 天台县| 宝兴县| 横峰县| 斗六市| 彰武县| 茶陵县| 仁化县| 延安市| 原平市| 甘南县| 滨州市| 越西县| 衡南县| 遂川县| 遵义县| 略阳县| 湟中县| 顺平县|