I am using a Docker droplet and I am trying to configure Nginx as a reverse proxy. When I type my IP in the browser I can see the HTML my page, but when I use my domain (mydomain.com) it doesn’t work. I notice that with Postman I can make a GET request HTTP and it loads the HTML page, on browser always try to use an HTTPS connection.
Here is my nginx.conf:
server {
listen 80;
listen [::]:80;
listen 443;
listen [::]:443;
server_name iamgonzales.dev www.iamgonzales.dev;
location ~ /.well-known/acme-challenge {
allow all;
root /usr/share/nginx/html;
}
root /usr/share/nginx/html;
index index.html;
}
Here is my docker-compose.yml
version: '3.1'
services:
letsencrypt-nginx-container:
container_name: 'letsencrypt-nginx-container'
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ./letsencrypt-site:/usr/share/nginx/html
networks:
- docker-network
networks:
docker-network:
driver: bridge
Here are all my droplet open doors:
root@docker:~# netstat -tulpn | grep LISTEN
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 740/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 951/sshd
tcp6 0 0 :::80 :::* LISTEN 5412/docker-proxy
tcp6 0 0 :::22 :::* LISTEN 951/sshd
tcp6 0 0 :::443 :::* LISTEN 5400/docker-proxy
Is there any conf that I missing??
Appreciate any help as I lost half day on this.
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!
Hi, @stgonzales
Before we deep dive into troubleshooting this, can you confirm that the domain name is pointed to your droplet’s IP address?
You can use our DNS lookup tool in order to check if the domain name is resolving from your droplet:
https://www.digitalocean.com/community/tools/dns
Let me know how it goes,
Regards, Alex
Heya,
here is an update on an older topic in case someone stumbles upon it
Based on the configuration and description, there are a few key points to consider:
SSL Configuration for Nginx:
Let’s Encrypt SSL Certificate:
letsencrypt-nginx-container, but it’s unclear if you’re actually using a tool like Certbot to obtain an SSL certificate.Nginx Configuration:
Docker Configuration:
Here’s an example of how you might adjust your Nginx configuration:
server {
listen 80;
listen [::]:80;
server_name iamgonzales.dev www.iamgonzales.dev;
location ~ /.well-known/acme-challenge {
allow all;
root /usr/share/nginx/html;
}
# Redirect all HTTP traffic to HTTPS
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name iamgonzales.dev www.iamgonzales.dev;
ssl_certificate /path/to/fullchain.pem; # Adjust with your SSL certificate path
ssl_certificate_key /path/to/privkey.pem; # Adjust with your SSL key path
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
In your docker-compose.yml, ensure the SSL certificates are correctly mapped:
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ./letsencrypt-site:/usr/share/nginx/html
- /path/to/letsencrypt:/etc/letsencrypt # Map the directory containing your SSL certificates
After making these changes, restart your Docker container:
docker-compose down
docker-compose up -d
Remember:
fullchain.pem) and key (privkey.pem) paths must be correctly set in your Nginx configuration.iamgonzales.dev and www.iamgonzales.dev to point to your server’s IP.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.