server 1 - has nginx and apache installed. apache listen port 8000, nginx listen port 80. nginx acting as TLS termination point, and load balancer.

server 2 - apache listen port 80

HTTPS is working perfectly.

problem is when traffic point to server 1 :

web page show as http://test.net:8000 and did not redirect to HTTPS and also expose port on address http://test.net:8000

im new to nginx, how do i improve my configuration blow:

upstream testpool {

server {

    server_name test.com test.net;

    listen 80 default_server;
    listen [::]:80 default_server;

    #redirect non http to https
    #return 404; # managed by Certbot
    #not recomended rewrite ^ https://$host$request_uri;
    return 301 https://$host$request_uri;


server {

    server_name test.com test.net;
    listen 443 ssl default_server;

    #ssl section, listen 443 is new way of ssl on;
    ssl_certificate /etc/letsencrypt/live/test.net/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/test.net/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    location / {

    proxy_pass http://testpool;
    include /etc/nginx/proxy_params;
    #return 301 https://$server_name$request_uri;

  • your two servers can't both listen on the same IP address... it'll cause conflicts. What's your goal here? – Thomas Ward Dec 18 '18 at 19:57
  • my bad, my typo of repeat the same IP address, but the configuration is correct. upstream has two servers and My goal is traffic comes in at port 80 it redirect to HTTPS – cnguyen Dec 18 '18 at 20:23

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.