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:
- Setting the certificates int the Nginx should not be an issue.
- Nginx will communicate with the back-end server using HTTPS only if it currently serves HTTPS.
- 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?
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
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