当前位置:   article > 正文

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"
  • 1

错误信息查询nginx后台日志可知:

tail -f /usr/local/nginx/logs/access.log
  • 1

错误配置如下:

  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;
		}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

经多次调试,发现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;
		}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

也可以匹配任何已 /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;
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

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;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/103699
推荐阅读
相关标签
  

闽ICP备14008679号