小编Mic*_*nov的帖子

nginx 代理给出 404 未找到

proxy_pass在本地计算机上的 Docker(Windows 下)中测试了 nginx 配置。

我的 nginx 配置文件:

server {
    listen  80;
    
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://example.com;
    }
}
Run Code Online (Sandbox Code Playgroud)

Dockerfile:

FROM nginx
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80 443
Run Code Online (Sandbox Code Playgroud)

然后构建图像并运行它:

docker run -d -p 8081:80 nginxproxy
Run Code Online (Sandbox Code Playgroud)

而且http://localhost:8081我从来没有到达http://example.com 代理不起作用。我总是收到404 未找到错误

为什么?

更新

docker exec nginxproxy nginx -T
Run Code Online (Sandbox Code Playgroud)

给出:

$ docker exec nginxproxy nginx -T
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful …
Run Code Online (Sandbox Code Playgroud)

nginx proxypass

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

nginx ×1

proxypass ×1