I have two servers:

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

server 2 - 192.168.0.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 {
    least_conn;
    server 192.168.0.1:8000;
    server 192.168.0.2:80;
    }

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 / {
    resolver 8.8.8.8;

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

    }
}
edited by kamaln7

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.

×
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

Jarland

Submit an Answer