I have successfully managed to install SSL via certbot into my Nginx Docker container,
but after installation, all traffic routed via HTTPS
refuses to connect.
curl https://www.example.com
or curl https://the_ip_of_server
curl: (7) Failed to connect to example.com port 443 after 9822 ms: Connection refused
~Port 443 is open on the server(AWS Lisghtsail)
curl http://www.example.com
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.21.6</center>
</body>
</html>
but when curl http://the_ip_of_server
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.21.6</center>
</body>
</html>
here is nginx.conf
#Limit Concurrency
limit_conn_zone $binary_remote_addr zone=per_ip:10m;
server {
server_name example.com www.example.com;
location / {
proxy_pass http://flask:8080/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
proxy_intercept_errors on;
limit_conn per_ip 12;
}
error_page 404 /notfound.html;
location /notfound.html {
root /var/www/html;
internal;
}
error_page 500 502 503 504 /maintenance.html;
location /maintenance.html {
root /var/www/html;
internal;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/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
}
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
server_name example.com www.example.com;
return 404; # managed by Certbot
}
docker-compose.yml
version: '3.7'
services:
flask:
build: ./Flask App
container_name: flask
restart: always
environment:
- APP_NAME=Env
expose:
- 8080
nginx:
build: ./Nginx
container_name: nginx
restart: always
ports:
- "80:80"