How to Set Up a Reverse Proxy with Nginx on CentOS Stream
An Nginx reverse proxy places a public-facing gateway in front of an application server. Nginx accepts the request, forwards it to a backend service, and returns the response while keeping the backend’s internal address hidden. This is common on CentOS Stream when an application listens on a local port such as 3000 or 8000.
This guide follows the current CentOS Stream workflow with dnf and systemd, from package installation through TLS, firewalld, and SELinux. Australian teams can adapt the example hostname to an .com.au or .au domain and position the proxy near workloads in AWS Sydney or Melbourne.
Prepare the CentOS Stream Host
Start with root access or a sudo-enabled account, then update the host and install Nginx:
sudo dnf update -y
sudo dnf install -y nginx policycoreutils-python-utils
sudo systemctl enable --now nginx
Confirm the result with systemctl is-active nginx, then request the default page locally using curl http://127.0.0.1. Keep the backend service on loopback or a private network; exposing its port directly would bypass the proxy’s TLS, access controls, and logging.
Configure Nginx as the Reverse Proxy
Assume the application already listens on 127.0.0.1:3000. Create a host-specific Nginx configuration rather than changing the packaged default site:
sudo vi /etc/nginx/conf.d/app.conf
server {
listen 80;
server_name app.example.com.au;
location / {
proxy_pass http://127.0.0.1:3000;
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;
}
}
The headers preserve the original client and protocol information, which the backend may need for URLs, sessions, and audit records. Test and reload the configuration with sudo nginx -t followed by sudo systemctl reload nginx; confirm routing with curl -H 'Host: app.example.com.au' http://127.0.0.1 before changing DNS.
When documenting the deployment, make labels unambiguous rather than calling every file an app download. A third-party Dutch download workflow illustrates why a generic label can leave users unsure which platform or version they are obtaining.
Add HTTPS with TLS
Create an A or AAAA record for app.example.com.au pointing to the proxy, confirm it resolves, and install Certbot from the repositories approved for your organisation. On CentOS Stream, EPEL commonly supplies the packages:
sudo dnf install -y epel-release
sudo dnf install -y certbot python3-certbot-nginx
sudo certbot --nginx -d app.example.com.au --redirect
Certbot obtains and installs the certificate, then configures Nginx to redirect HTTP to HTTPS. Check the renewal timer and run a dry test with sudo systemctl list-timers | grep certbot and sudo certbot renew --dry-run; certificate renewal must be tested before an expiry becomes an outage.
Control SELinux and firewalld
On a host using firewalld, allow inbound web traffic with these commands. They leave SSH alone while opening the standard web ports:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
SELinux can still block Nginx from reaching a non-standard backend port. Enable the targeted permission and inspect recent denials if needed:
sudo setsebool -P httpd_can_network_connect 1
sudo ausearch -m AVC -ts recent
A cloud firewall is separate from the host firewall. For an instance in an Australian cloud region, permit ports 80 and 443 in the security group as well, and avoid opening 3000 or 8000 to the internet.
Diagnose Proxy Routing
Work from the outside in: test DNS, confirm listeners, test the backend, and then inspect Nginx:
getent hosts app.example.com.au
sudo ss -ltnp | grep -E ':(80|443|3000)\b'
curl http://127.0.0.1:3000/
sudo tail -f /var/log/nginx/error.log
If a port is missing, this guide to monitoring network sockets explains how to compare listening services with ss and netstat. A 502 Bad Gateway usually points to an unreachable backend, a wrong port, or an SELinux denial; test the upstream directly before changing Nginx.
For an arvo health check, set the host time zone deliberately to Australia/Sydney or Australia/Melbourne, while retaining UTC in shared logs. IP addresses captured by Nginx may also be personal information under the Privacy Act 1988, so limit log access and define a retention period.
Routine Care for the Proxy
Nginx unit messages may also appear in the systemd journal; use journalctl filter examples to isolate service events by time or priority. For runbooks aimed at non-administrators, name the exact host, certificate, and configuration file so nobody has to infer which component they are changing.
- Bind the backend to loopback or a private interface, and block direct public access to its port.
- Keep TLS private keys readable only by root, and verify automated certificate renewal on a schedule.
- Monitor certificate expiry, Nginx status, disk use, upstream latency, and rising 4xx or 5xx response rates.
- Record DNS records, open ports, configuration ownership, backup locations, and rollback steps in the team handover.
Run nginx -t after every configuration change and reload rather than restart unless a restart is required. Keep the upstream service and Nginx package updated during a controlled maintenance window, especially for Australian businesses operating across daylight-saving changes and multiple support shifts.
The operating essentials
The finished setup has a clear path: public DNS reaches Nginx, Nginx forwards to the healthy backend, and TLS protects data in transit. Host firewall rules, SELinux policy, and sensible headers then determine who can reach what and what the application can learn about each request.
The essential lesson is to treat the reverse proxy as a controlled public gateway, not a one-off configuration file. A successful curl on the CentOS Stream server proves only part of the path; reliable service means that users in Perth, Brisbane, Sydney, or Melbourne can reach the same secure and monitored endpoint.