what's wrong with my nginx configuration

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. did not redirect to https 2. 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 {


    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 {

    listen 443 ssl default_server;
    #ssl section, listen 443 is new way of ssl on;
    ssl_certificate /etc/letsencrypt/live/; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/; # 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;

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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