2

I am trying to use nginx on the host machine as the reverse proxy before my nextjs app which is deploy on a swarm mode. But it always shows 404 not found error with path like _next/*****/page/index.js.

When I connect to http://machine-host-name:3000 it works well, but connect to http://machine-hos-name/nextjs it shows the 404 not found error.

Here is my nginx setting

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/;
   } 
}

Not sure which part is incorrect, kindly give my some advise.

Thank you.

1
  • Try to pass the $uri at the end of proxy_pass Commented Jul 13, 2018 at 13:01

1 Answer 1

0

That method of reverse proxying is an anti-pattern.

  1. Your proxy should be in a swarm service as well.
  2. It should use a swarm-api-aware proxy agent that can update your proxy based on the changes swarm makes.

Two good ones are Docker Flow Proxy and Traefik.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.