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

November 11, 2019 103 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

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?

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!