Search code examples
nginxvirtual-directory

How do I set up nginx to serve data from a port?


I have nginx serving a page on port 80.

server {
listen   80;
server_name .example.com;
root       /var/www/docs;
index      index.html;
}

I also have a service running a server on port 9000. How do I set up a virtual directory in nginx (such as /service) to serve whatever is on port 9000? I am unable to open other ports, so I would like to serve this through some kind of virtual directory on port 80.


Solution

  • Start with that (but you definetly will need more directives to make your server normally answering on this subdirectory):

    location /something {
        proxy_pass http://localhost:9000/;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
    }