gpt4 book ai didi

docker - 在主机上使用Nginx反向代理在Docker中部署nextjs应用

转载 作者:行者123 更新时间:2023-12-02 18:29:40 26 4
gpt4 key购买 nike

我试图在以群集模式部署的nextjs应用程序之前在主机上使用nginx作为反向代理。但是它总是显示404 not found error with _next/*****/page/index.js这样的路径。

当我连接到http://machine-host-name:3000时效果很好,但是连接到http://machine-hos-name/nextjs则显示404 not found错误。

这是我的nginx设置

server {
listen 80 default_server;
listen [::]:80 default_server;

index index.html index.htm index.nginx-debian.html;
server_name _;

location /nextjs {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;

proxy_pass http://localhost:3000/;
}
}

不确定哪个部分不正确,请给我一些建议。

谢谢。

最佳答案

反向代理的方法是一种反模式。

  • 您的代理服务器也应该处于群集服务中。
  • 它应该使用可识别swarm-api的代理程序,该代理程序可以根据swarm所做的更改来更新您的代理程序。

  • 好的两个是 Docker Flow ProxyTraefik

    关于docker - 在主机上使用Nginx反向代理在Docker中部署nextjs应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51203178/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com