what's wrong with my nginx configuration

December 18, 2018 538 views

I have two servers:

server 1 - - have nginx and apache2 installed
apache listen port 8000
nginx listen port 80
nginx is a load balancer and TLS termination

server 2 - - apache listen port 80

https is working perfectly.

the problem is : if the traffic is direct to server 1 then
1. http://test.net:8000 did not redirect to https
2. http://test.net:8000 expose port 8000, when I expected it hidden to the world

I’m new to nginx, how do I improve my configuration beblow:


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;

1 Answer

Hey friend,

I would propose that you are mostly doing this correctly. You could redirect port 8000 to 443, but you want to hide 8000 anyway so I’d just block it in the firewall like this:

iptables -I INPUT -p tcp --dport 8000 -j ACCEPT


Have another answer? Share your knowledge.