-
Notifications
You must be signed in to change notification settings - Fork 12
Nginx Configuration on Virtual Machine
This document is also available in Portuguese
Create the directories that will be used.
mkdir data
cd data
mkdir nginx
Access https://www.gandi.net/en
- Create the domain, on domain section, using the machine's external IP address.
Create the file at /nginx/data/nginx
then replace the placeholder values. Replace projectname with the name of your project. Change the server name from example.org to your own domain, using your server's IP/port.
upstream projectname {
server 10.0.0.10:8000;
}
server {
listen 80;
server_name example.org;
location / {
return 301 https://$host$request_uri;
}
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
}
server {
listen 443 ssl;
server_name example.org;
location / {
proxy_pass http://projectname;
}
ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
Create the docker-compose.yml
file on the ~/nginx
directory.
Then add the following configurations to the file.
version: '3'
services:
nginx:
image: nginx:1.15-alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./data/nginx:/etc/nginx/conf.d
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
# command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
certbot:
image: certbot/certbot
volumes:
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
# entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
Create a new file called init-letsencrypt.sh
on the ~/nginx
path.
Add the content bellow to the new file for certificate generation.
Link to access the script to be added
Change the domain to the domain created on Gandi.net.
Set the file as executable, with:
chmod a+x init-letsencrypt.sh
Run the script to generate the certificate.
./init-letsencrypt.sh
To verify registration info about a domain, host or IP DNS, run the command bellow. Use your domain info.
nslookup example.org
The result should be like this
Server: 0.0.0.0
Address: 0.0.0.0#53
Non-authoritative answer:
Name: example.org
Address: 192.168.0.0
Run the project with the command
sudo docker-compose up --build -d
Open the browser and insert your domain. You should be redirected to the application page.