nginx – proxy_pass /subfolder – destination files 404'ing. Rewrite rule required?

Posted November 11, 2019 12k views

I have two servers running nginx:

Server 1 has a range of projects on it
Server 2 has a new Vue/Nuxtjs (node)

On server 1 I have set up a proxy_pass to the static IP of server 2 where my node based app is running. So the goal is for users to just see http://domain.tld/folder, http://domain.tld/folder/login etc when they browse the site

Server 1:

location /folder/ { 
  proxy_pass; // IP of server 2

Server 2:

location / {
  proxy_pass http://localhost:3000;

This works partly but all assets are 404. And when clicking links the browser visits http://domain.tld/login

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

Hello, @ltyler

You’ll need to use/add some extra rules in order to setup this. You can use proxysetheader to set this. You can try with the following snippet of code on server 1:

    location /folder {
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Let me know how it goes.


Hi Alex - thanks for this. It did not seem to have any effect (I made sure to restart nginx)

Do I need to do anything on server 2?