By Cong Nguyen
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;
}
}
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!
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.