赞
踩
访问地址:http://IP:端口/ceshi/chael/coonMouthpiece
配置后台服务反向代理的时候报:
[31/Dec/2020:14:27:43 +0800] "POST /ceshi/chael/coonMouthpiece HTTP/1.1" 404 0 "-" "PostmanRuntime/6.4.1"
错误信息查询nginx后台日志可知:
tail -f /usr/local/nginx/logs/access.log
错误配置如下:
server {
listen 80;
server_name localhost;
location /ceshi {
proxy_pass http://192.168.1.110:8080;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
经多次调试,发现http://192.168.1.110:8080/地址后少加了 /,加上之后再次调用就转发成功了
正确配置:
server {
listen 80;
server_name localhost;
location /ceshi/ {
proxy_pass http://192.168.1.110:8080/;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
也可以匹配任何已 /images/ 开头的任何查询并且停止搜索。任何正则表达式将不会被测试。
IP地址后面跟channel 例如:/chael/coonMouthpiece
upstream tomcat{
server 192.168.1.121:8083;
}
server {
listen 8080;
server_name localhost;
location ^~ /channel/{
proxy_pass http://tomcat;
}
}
或者
location /wu/ {
proxy_pass http://192.168.1.110:8082/wu/;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
http://192.168.1.1:8081/chael/servi_restful/rest/polHandler/xaCancelT
另外一种,代理后台之后,不需要增加地址的方式
location /chael/servi_restful/ {
proxy_pass http://192.168.1.25:8210/chael/servi_restful/;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
或者
location ^~ /chael/servi_restful/ {
proxy_pass http://192.168.1.25:8210/chael/servi_restful/;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。