Nginx – How to Listen to Different Ports

azurelinuxnginxvirtual-machines

I created one Nginx with one Linux Azure VM, is it possible to make nginx listen to different ports so that when I change the port number, the content would be different. I found there would be a collision if I created two or more ports related to HTTP on VM. Can anyone help me with that?

Best Answer

Yes, it is.

What you probably want is multiple "server" stanzas, each with a different port, but possibly (probably?) the same server_name, serving the "different" content appropriately within each one, maybe with a different document root in each server.

Full documentation is here: http://nginx.org/en/docs/http/server_names.html

Example:

server {
    listen       80;
    server_name  example.org  www.example.org;
    root         /var/www/port80/
}

server {
    listen       81;
    server_name  example.org  www.example.org;
    root         /var/www/port81/
}
Related Topic