Skip to main content How to proxy_pass to root adress of server : r/nginx
Go to nginx
•

How to proxy_pass to root adress of server

I am trying to learn nginx and are tying to make a simple proxy_pass.

I have a simple node application running on http://localhost:9966

My nginx rule is

location /site1 {proxy_set_header X-Real-IP $remote_addr;proxy_set_header Host $http_host;proxy_set_header X-Forwarded-Proto https;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://localhost:9966;}

But what i am getting is /usr/share/nginx/html/site1" failed (2: No such file or directory)

What I am expecting is a request to http://localhost:9966 which will in return respond with the index.html page.

Korbit’s AI-Powered Code Review Agent helps your team ship better code, faster.
Thumbnail image: Korbit’s AI-Powered Code Review Agent helps your team ship better code, faster.
Sort by:
Best
Open comment sort options

The error /usr/share/nginx/html/site1" failed (2: No such file or directory) suggests your location block isn't being matched at all and nginx is trying to serve a file instead, the reason why is hard to say without seeing the rest of the config.

Even if it did work, because you are using /site1 nginx will proxy the request to localhost:9966/site1 as well. This might not be what you want and in general running something in a subfolder complicates things a lot.

Thanks for your respons.
Maybe what I want to do is not possible, or not how nginx work.

I will be running several different applications on the same server from different ports.

If i run localhost:9966 in my browser I get to the application as i want. But I want to reach it when i go to localhost:8000/app1 Another application will respond on localhost:8000/app2 and so on.

I did manage to get upstream to be localhost:9966/site1 when I hit localhost:8000/site1. But I was hoping that would proxy to localhost:9966 and not localhost:9966/site1

More replies
More replies