使用主机上的nginx反向代理在docker中部署nextjs应用程序

使用主机上的nginx反向代理在docker中部署nextjs应用程序,docker,nginx,docker-swarm,next.js,Docker,Nginx,Docker Swarm,Next.js,在我的nextjs应用程序部署在swarm模式之前,我试图在主机上使用nginx作为反向代理。但它总是显示404未找到错误,路径类似于\u next/*****/page/index.js 当我连接到http://machine-host-name:3000它工作正常,但连接到http://machine-hos-name/nextjs它显示404未找到错误 这是我的nginx设置 server { listen 80 default_server; listen [::]:80 d

在我的nextjs应用程序部署在swarm模式之前,我试图在主机上使用nginx作为反向代理。但它总是显示404未找到错误,路径类似于
\u 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/;
   } 
}
不确定哪一部分是错误的,请给我一些建议


谢谢。

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

  • 您的代理也应该在swarm服务中
  • 它应该使用swarm api感知代理,该代理可以根据swarm所做的更改更新代理

  • 两个好的是and。

    尝试传递代理传递末尾的
    $uri