Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NGINX: How to setup multiple port in one server or domain name?

Tags:

nginx

I am new to nginx. I am having trouble with my setup, I want my server to run with multiple port on public.

For example:

server {
  listen 443 ssl;
  server_name <https - mydomainname>;
  ssl_certificate <location cert>;
  ssl_certificate_key <location key>;
    location /tags.txt {
      add_header 'Access-Control-Allow-Origin' '*';
    }
}

From the above setup I am now able to access <https - mydomainname> perfectly. But what if I have http://localhost:6006 and http://localhost:5005 multiple ports in my localhost and I want to publish it. I tried to access it using this https - mydomainname : port 6006 and https - mydomainname : port 5005 but it fails.

Should I make a setup for another port? Like for port 6006

server {
 listen 6006 ssl;
 server_name <https - mydomainname>;
 ssl_certificate <location cert>;
 ssl_certificate_key <location key>;
  location /tags.txt {
    add_header 'Access-Control-Allow-Origin' '*';
    proxy_pass http://localhost:6006;
  }
}

and port 5005

server {
 listen 5005 ssl;
 server_name <https - mydomainname>;
 ssl_certificate <location cert>;
 ssl_certificate_key <location key>;
  location /tags.txt {
    add_header 'Access-Control-Allow-Origin' '*';
    proxy_pass http://localhost:5005;
  }
}

How to fix it?

like image 598
Michael Blanza Avatar asked Jun 27 '16 10:06

Michael Blanza


People also ask

How do I run multiple ports on Nginx?

To make Nginx Listen on multiple ports for a single virtual host file, you can add multiple listen directives. If you want to make Nginx listen for different virtual hosts on different ports, you can use different ports in listen directive in different virtual host files. It's that easy!

Can a single SSL server certificate cover multiple ports per domain name?

Yes, a single SSL server certificate can cover multiple ports for the same domain name.

How many connections can an Nginx server handle?

How many connections can NGINX handle? Each NGINX worker can handle a maximum of 512 concurrent connections. In newer versions, NGINX supports up to 1024 concurrent connections, by default. However, most systems can handle more.


1 Answers

You can have multiple listen directives per server:

server {
 listen 5005 ssl;
 listen 6006 ssl;
 server_name <https - mydomainname>;
 ssl_certificate <location cert>;
 ssl_certificate_key <location key>;
  location /tags.txt {
    add_header 'Access-Control-Allow-Origin' '*';
  }
}
like image 128
amq Avatar answered Jan 01 '23 23:01

amq