I'm trying to make my website be accessible throught these 4 options (2 throught HTTPS, and 2 throught HTTP to be redirected to HTTPS): https://www.example.com, https://example.com, http://www.example.com and http://example.com, but the last one is the only one which doesn't work, for some reason, instead of redirecting from http://example.com to https://example.com, it goes to the VPS server IP with the port at the end, example http://123.456.0.789:3000 and it returns a timeout error.
My domain isn't in the same place as the VPS server, so I changed the domain records type to match the VPS IP. A (@) -> VPS IP / A (www) -> VPS IP / AAAA (@) -> VPS IPV6
Here is my Nginx config:
server {
server_name www.example.com example.com;
location /socket.io/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://localhost:3000;
}
location / {
proxy_pass http://localhost:3000;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; # manage>
ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; # mana>
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name www.example.com example.com;
return 404; # managed by Certbot
}