Deploying a New Service in UAT Environment with Docker and Nginx
This guide provides a step-by-step approach to deploy a new service in the UAT environment using Docker, configure it in Nginx, and secure it with SSL.
1. Create a Domain
- Choose a domain or subdomain for the new service, for example:
newservice.uat.example.com
- Add an A or CNAME record in your DNS provider pointing the domain to your UAT server’s public IP.
2. Configure Nginx
- Open the UAT Nginx configuration file:
sudo nano /home/ubuntu/project/hei-core-new/nginx.uat.conf
- Add a new server block for the service:
server {
listen 443 ssl http2;
server_name newservice.uat.example.com;
ssl_certificate /etc/letsencrypt/live/newservice.uat.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/newservice.uat.example.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
proxy_pass http://<container_name>;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Ssl on;
}
}
Notes:
Replace <container_name> with the Docker container name running your service.
If the service exposes a specific internal port, append it in the proxy_pass URL, e.g., http://<container_name>:<container_port>.
Save and close the file.
3. Generate SSL Certificate
- Install Certbot if it is not already installed:
sudo apt update
sudo apt install certbot python3-certbot-nginx -y
- Generate the SSL certificate and configure Nginx automatically:
sudo certbot --nginx -d newservice.uat.example.com
- Follow the interactive prompts to complete HTTPS configuration.
Tip: Enable automatic renewal of SSL certificates:
sudo crontab -e
# Add the following line to renew certificates daily
0 3 * certbot renew --quiet
4. Update Docker Compose
- Stop current Docker services in UAT:
docker-compose -f docker-compose.yaml -f docker-compose.uat.yaml down
- Bring up the updated services:
docker-compose -f docker-compose.yaml -f docker-compose.uat.yaml up -d
- Verify that your new service container is running:
docker ps
5. Verify Deployment
- Access the new service via the domain:
https://newservice.uat.example.com
- Check logs if any issues occur:
docker logs <container_name>
sudo journalctl -u nginx -f
Best Practices
Always back up nginx.uat.conf before making edits.
Use docker-compose down only when necessary; up -d can often apply changes without downtime.
Ensure firewall rules allow HTTP (80) and HTTPS (443) traffic.
Monitor logs after deployment to catch configuration issues early.
Schedule automatic SSL renewal using Certbot’s cron job.
Comments
Join the discussionNo comments yet. Be the first to comment.