Nginx返回404未找到

时间:2018-08-05 18:27:28

标签: nginx

我需要将流量example.com/api路由到在端口8080上运行的网络服务器。这是我的conf文件,

server {
            listen 80;
            server_name localhost;


            location /api {
                    proxy_pass http://127.0.0.1:8080;
                    add_header Content-Type text/plain;
                    proxy_set_header Host $server_name;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            }
    }

我收到以下HTML的回复

<html>
<head><title>404 Not Found</title></head>
    <body bgcolor="white">
        <center><h1>404 Not Found</h1></center>
        <hr><center>nginx/1.10.3 (Ubuntu)</center>
    </body>
</html> 

2 个答案:

答案 0 :(得分:0)

我想您想将http://your.domain/api/abcdef重定向到

http://127.0.0.1:8080/abcdef

而不是

http://127.0.0.1:8080/api/abcdef

为此,您需要修改

proxy_pass http://127.0.0.1:8080;

proxy_pass http://127.0.0.1:8080/;

答案 1 :(得分:0)

我通过更改位置来完成这项工作。

将位置/api更改为位置/api/

相关问题