NGINX with multiple listen ports.

I have nginx running as a reverse proxy successfully. I am looking to simplify the listen ports..

Is there a way to create 2 or more listen ports for a given entry?

for example

server {
    listen 80, 443;
    server_name example.domain.com;
    location / {
        proxy_pass http://192.168.15.15;
    }
}
LVL 2
beatifiedAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nociSoftware EngineerCommented:
Yes that can be done:

server {
  listen 80;
  listen 443;
  listen 1234;
  server_name www.example.com;
  location / {
     proxy_pass http://192.168.15.15;
  }
}

Open in new window

Are you aware that port 80 needs different handling from 443 because of the SSL / TLS  layers involved?
the port will not be used on a connect to a backend.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
beatifiedAuthor Commented:
No I wasn't are you saying that the ssl connection is connecting to Nginx and not the destination IP? in other words SSL has be be installed and configured on the Nginx server?
0
nociSoftware EngineerCommented:
You cant connect aan SSL connection to another non-ssl  port
So you need at least to handle 2 sets one SSL and one non-SSL....
Then if you differentiate on servername, the server entries are match on servername, there can be one catch all: " server_name _; "

Your example forwards port 443 (HTTPS) on the the backend server port 80 (HTTP)
Yes as you cannot transparently proxy  HTTPS this way, it at least needs to be decoded before the HTTP from the SSL/TLS has been recognized...

Maybe you should look into HAPROXY this is probably better equiped .  (HAPROXY  CAN transparantly proxy HTTPS, in TCP mode).
0
Prabhin MPEngineer-TechOPSCommented:
Hi ,
you can add multiple listen port. Yourself need to make sure that which one need to listen as SSL and non ssl, According to that you need to just configure the SSL certificates.

Hope this will help you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Proxy bypass

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.