Nginx反向代理后台报404遇到的解决方法
作者:被生活耽误的旅行者
Nginx反向代理404错误通常是由服务器配置不正确、文件路径不正确、文件权限不正确、文件名大小写不正确等,本文主要介绍了Nginx反向代理后台报404遇到的解决方法,感兴趣的可以了解一下
访问地址: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; }
到此这篇关于Nginx反向代理后台报404遇到的解决方法的文章就介绍到这了,更多相关Nginx反向代理404内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!