Operations 3 min read

Nginx Server Configuration: Proxy Pass, URL Rewrites, SSL, and Error Pages

This article provides a step‑by‑step guide to configuring Nginx for both HTTP and HTTPS, including how to set up separate proxy passes for multiple APIs, define URL rewrite rules, configure SSL certificates, and customize error page handling using concrete configuration examples.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Nginx Server Configuration: Proxy Pass, URL Rewrites, SSL, and Error Pages

The guide explains how to configure an Nginx server to listen on port 80, serve static files, and proxy requests to different backend APIs. It also shows how to define custom error pages and enable HTTPS with SSL certificates.

server { listen 80; root /data/php/; server_name api.open.com; # URL rewrite for test1api location ^~ /test1api/ { proxy_set_header Host test1api.open.com; proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for; proxy_set_header X-real-ip $remote_addr; proxy_pass http://test1api.open.com/; } # URL rewrite for test2api location ^~ /test2api/ { proxy_set_header Host test2api.open.com; proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for; proxy_set_header X-real-ip $remote_addr; proxy_pass http://test2api.open.com/; } # Custom error pages error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }

For HTTPS, the configuration adds SSL settings and points to the certificate and key files.

server { listen 443; root /data/php/; server_name api.open.com; ssl on; ssl_certificate /usr/local/ssl/1_api.open.com_bundle.crt; ssl_certificate_key /usr/local/ssl/1_api.open.com.key; }

Repeated sections illustrate how the same URL rewrite blocks can be placed in both HTTP and HTTPS server blocks. The article ends with a decorative line and a list of recommended reading links.

proxyNginxError HandlingServer ConfigurationURL RewriteSSL
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.