This guide covers setting up Nginx as a reverse proxy for multiple microservices with file serving and authentication on Amazon Linux.
sudo dnf install tmux
- Main App: Port 3000 (Frontend application)
- Metadata Service: Port 5000 (API metadata endpoints)
- Upload Service: Port 5002 (File upload handling)
- Auth Service: Port 5001 (JWT token validation)
- File Serving: Static files served by Nginx with auth validation
- Amazon Linux EC2 instance
- Python 3.8+
- SSL certificates (cert.pem and key.pem)
# Update system
sudo dnf update -y
# Install Nginx
sudo dnf install -y nginx
# Enable and start Nginx
sudo systemctl enable nginx
sudo systemctl start nginx
# Install Python and pip
sudo dnf install python3 python3-pip -y
# Install ACL utilities ( file/directory permissions utility )
sudo dnf install acl -y
Deploy the upload service code on "/home/ec2-user/services/app". Setup the main application on port 3000.
Deploy the upload service code on "/home/ec2-user/services/metadata". Setup the metadata service to run on port 5000.
Deploy the upload service code on "/home/ec2-user/services/metadata/utils". Setup the upload service to run on port 5002.
# Create application directories
sudo mkdir -p /home/ec2-user/services/metadata/downloads/audio
sudo mkdir -p /home/ec2-user/services/metadata/downloads/images
sudo mkdir -p /home/ec2-user/nginx
# Set ACL to allow nginx read access
sudo setfacl -R -d -m u:nginx:rx /home/ec2-user/services/metadata/downloads/audio
sudo setfacl -R -d -m u:nginx:rx /home/ec2-user/services/metadata/downloads/images
# Verify ACL settings
getfacl /home/ec2-user/services/metadata/downloads
Copy the Nginx configuration from the examples directory:
sudo cp examples/nginx/nginx.conf /etc/nginx/nginx.conf
See examples/nginx/nginx.conf for the complete configuration.
Copy the auth service from examples:
cp examples/services/auth/app.py /home/ec2-user/services/auth/app.py
See examples/services/auth/app.py for the complete implementation.
Copy systemd service files from examples:
# Copy service files
sudo cp examples/systemd/auth-service.service /etc/systemd/system/
See the individual service files in examples/systemd/ for configuration details.
# Reload systemd
sudo systemctl daemon-reload
# Enable and start services
sudo systemctl enable auth-service upload-service metadata-service nginx
sudo systemctl start auth-service upload-service metadata-service
# Check status
sudo systemctl status auth-service upload-service metadata-service nginx
# Nginx logs
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/nginx/access.log
# Service logs
sudo journalctl -u auth-service -f
# Check ACL permissions
getfacl /home/ec2-user/services/metadata/downloads
# Test nginx access
sudo -u nginx ls -la /home/ec2-user/services/metadata/downloads