Configuring NGINX for Spinup Load Balancers
This guide explains a basic configuration of NGINX on your EC2 instance to serve traffic on ports 80 / 443.
Prerequisites
EC2 instance running Ubuntu, AlmaLinux, or Amazon Linux
Administrative (sudo) access
A web application, and the port it is hosted on (
YOUR_APP_PORT
)
Enable Firewall Access
Navigate to your Space in the Spinup portal
Open the Firewall tab
Add rules allowing traffic to ports 80 and 443.
Installation
Ubuntu
sudo apt update && sudo apt install nginx
AlmaLinux/Amazon Linux
sudo dnf install nginx
sudo setsebool -P httpd_can_network_connect 1
SSL Certificate Setup
Generate a self-signed certificate for backend HTTPS:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/ssl/private/nginx-selfsigned.key \
-out /etc/ssl/certs/nginx-selfsigned.crt
NGINX Configuration
Create /etc/nginx/conf.d/app.conf
:
server {
listen 80;
listen 443 ssl;
server_name _;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
location / {
proxy_pass http://localhost:YOUR_APP_PORT;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Replace YOUR_APP_PORT
with your application's port number.
Enable and Start NGINX
sudo nginx -t
sudo systemctl enable nginx
sudo systemctl start nginx
Verification
Check that NGINX is running:
sudo systemctl status nginx
From a web browser, attempt to connect to http://YOUR_IP and https://YOUR_IP. If you see your web application, you are all set!
, multiple selections available,