location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Reverse Proxy Setup
Complete Setup Guide
This guide will walk you through the complete process of setting up a reverse proxy with Nginx. Follow the steps in order for the best results.
Step 1: Domain & DNS Setup
First, configure your domain to point to your server. This must be done before setting up SSL certificates.
Configure Nginx as a reverse proxy:
server {
# -------------------------------------------------------
# HTTP -> HTTPS (men tillad ACME-challenges for cert fornyelse)
server {
if ($host = api.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name api.example.com;
# ACME (Let's Encrypt) – lad certbot validere uden at blive redirectet
location ^~ /.well-known/acme-challenge/ {
root /var/www/letsencrypt;
allow all;
}
return 301 https://api.example.comk$request_uri;
}
# HTTPS -> din NGINX-egg / webservice på port
server {
listen 443 ssl http2;
server_name api.example.com;
# Let's Encrypt certifikater
ssl_certificate /etc/letsencrypt/live/docs.mrfaws.dk/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/docs.mrfaws.dk/privkey.pem; # managed by Certbot
# Fornuftige TLS-indstillinger
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# Sikkerheds-headers
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options SAMEORIGIN always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
# Proxy til din specifikke Pterodactyl-server (HTTP på 3000)
location / {
proxy_pass http://127.0.0.1:3000;
# Vigtige headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# WebSocket support (hvis nødvendigt)
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Timeouts (så builds/uploads ikke dør for hurtigt)
proxy_read_timeout 300;
proxy_send_timeout 300;
}
}
}
Load Balancing
Set up load balancing across multiple backend servers:
Set up load balancing across multiple backend servers:
upstream backend {
server 127.0.0.1:3000 weight=3;
server 127.0.0.1:3001 weight=2;
server 127.0.0.1:3002 backup;
}
server {
listen 80;
server_name app.example.com;
location / {
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Domain & DNS Setup
Before configuring your reverse proxy, ensure your domain is properly set up:
DNS Configuration Interface
Configure DNS records for your domain. This interactive tool shows you how to set up different record types:
Edit DNS record example.com
DNS changes can take from 1 to 24 hours to take effect, but will be written to the zone immediately.
A Record Guide
A records map domain names to IPv4 addresses. Use this to point your domain to a server.
Example A Record:
example.com A 45.133.74.72
⚠️ Warning: Changing DNS records can greatly affect the availability of your domain
We DO NOT recommend you to change your DNS records unless you understand their function.
Verify DNS propagation:
# Check if DNS is working
dig example.com A
nslookup example.com
# Test from different locations
dig @8.8.8.8 example.com A
dig @1.1.1.1 example.com A
Step 2: Generate Nginx Configuration
Create a custom Nginx configuration file for your domain and backend application:
Configuration Generator
Fill in your details below to generate a custom Nginx configuration file:
Features
Performance
# Your configuration will appear here...
Step 3: Deploy Configuration
Save your generated configuration file and deploy it to your server:
1) Create configuration file:
# Create new site configuration (replace 'your-domain.com' with your actual domain)
sudo nano /etc/nginx/sites-available/your-domain.com
# Or upload your downloaded file
sudo cp ~/your-domain.com-nginx.conf /etc/nginx/sites-available/your-domain.com
2) Enable the site:
# Create symbolic link to enable site
sudo ln -sf /etc/nginx/sites-available/your-domain.com /etc/nginx/sites-enabled/your-domain.com
3) Test and activate:
# Test configuration syntax
sudo nginx -t
# If test passes, reload Nginx
sudo systemctl reload nginx
Step 4: SSL Certificate (Optional)
If you didn't include SSL in your configuration, you can add it using Certbot:
Generate SSL certificate:
# Install Certbot (if not already installed)
sudo apt install certbot python3-certbot-nginx
# Generate certificate for your domain
sudo certbot --nginx -d your-domain.com -d www.your-domain.com
Step 5: Management & Troubleshooting
Use these commands to manage and troubleshoot your reverse proxy:
Enable debug logging temporarily by adding error_log /var/log/nginx/debug.log debug; to your server block. Remember to remove it after debugging as it can impact performance.