Skip to content

muza-music/muza-nginx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Nginx Microservices Setup Guide

This guide covers setting up Nginx as a reverse proxy for multiple microservices with file serving and authentication on Amazon Linux.

Install tmux

sudo dnf install tmux

Architecture Overview

  • 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

Prerequisites

  • Amazon Linux EC2 instance
  • Python 3.8+
  • SSL certificates (cert.pem and key.pem)

1. Nginx Installation and Setup

Install Nginx

# 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 Additional Packages

# Install Python and pip
sudo dnf install python3 python3-pip -y

# Install ACL utilities ( file/directory permissions utility )
sudo dnf install acl -y

Main application (Port 3000)

Deploy the upload service code on "/home/ec2-user/services/app". Setup the main application on port 3000.

Metadata Service (Port 5000)

Deploy the upload service code on "/home/ec2-user/services/metadata". Setup the metadata service to run on port 5000.

Upload Service (Port 5002)

Deploy the upload service code on "/home/ec2-user/services/metadata/utils". Setup the upload service to run on port 5002.

2. Directory Structure Setup

# 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

3. File Permissions and ACL Configuration

Set up proper permissions for file access

# 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

4. Nginx Configuration

Main Nginx Configuration

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.

5. Python Microservices

Auth Service (Port 5001)

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.

7. Systemd Service Files

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.

8. Start Services

# 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

10. Troubleshooting

Check logs

# 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

Verify file permissions

# Check ACL permissions
getfacl /home/ec2-user/services/metadata/downloads

# Test nginx access
sudo -u nginx ls -la /home/ec2-user/services/metadata/downloads

About

Deployment eamples based on nginx proxy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published