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

时间:2018-07-06 04:47:51

标签: docker nginx docker-swarm next.js

我试图在以群集模式部署的nextjs应用程序之前将主机上的nginx用作反向代理。但是它始终显示404未找到错误,路径为_next/*****/page/index.js

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

这是我的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/;
   } 
}

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

谢谢。

1 个答案:

答案 0 :(得分:1)

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

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

两个不错的人是Docker Flow ProxyTraefik