Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Here the scenario.

example.com server, serves either 80 or port depends on user's choice.

This server is to be moved behind an instance of Nginx which will act as reverse proxy (and load balancer) and shall serve HTTP and HTTPS accordingly.

Note:

  1. Setting the certificates int the Nginx should not be an issue.
  2. Nginx will communicate with the back-end server using HTTPS only if it currently serves HTTPS.
  3. Nginx to support multiple virtual hosts, (i.e. multiple domains).

Point is, all examples I have come across so far are dealing in cases where http and https are served in different sub-domains, e.g.

server_name www.example.com;

and

server_name secure.example.com;

Question is, what is the configuration for such case?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

As your SSL side of things will not be in the same virtual host config you will need to have this in two seperate server {} config directives.

You should be able to do similar

server {
        listen       80 default;
        server_name  example.com _;
        ....
}
server {
        listen       443 default;
        server_name  example.com _;
        ....
}

As you have two seperate listen ports you will be able to have multiple instances of the same virtual host name - one per port (80 being http, 443 being https)

You may want to look at using an include for your common configuration between the two server{} directives to allow you to not have to repeat your config in the file

For Example

server {
        listen       80 default;
        include /etc/nginx/conf/common.conf;    }
server {
        listen       443 default;
        include /etc/nginx/conf/common.conf;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.