How to self-host a website using NGINX as a Reverse Proxy

This guide can be used to route traffic from multiple domain names to specific web servers on your local network. I recommend using a dynamic dns service to give your external IP address a friendly URL.

After getting my site running on localhost:8080 on my Mac, I then configured NGINX to route web traffic based on the domain name (the reverse proxy). This allows me to run multiple websites using one public IP address on port 80, rather than using 8080 or 8081 (which would be a simple case of port-forwarding).

On my Mac, I used homebrew to install nginx:

brew install nginx

Then, forward all web traffic on your router to the computer running nginx.

port_forwarding

Finally, drop in the config at /usr/localhost/etc/nginx/nginx.conf

  • Make sure to change 192.168.X.XX:8080 to the correct IP address and port

worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
server_name site1.example.com;
# app1 reverse proxy follow
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.1.10:8080/;
}
}
server {
server_name site2.example.com;
# app1 reverse proxy follow
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.1.11:8080/;
}
}
include servers/*;
}
view raw nginx.conf hosted with ❤ by GitHub

Then, if your reverse proxy is set up properly, NGINX will route the traffic to the corresponding sites anywhere within your local network. Slick!

My use of this reverse proxy was to self-host an instance of Atlassian JIRA, which is a resource-intensive project management suite.

Side notes: While this is a good way to get a website running, I would recommend paying for proper hosting for improved uptime and security. In the future, I might justify paying for robust hosting or simply use Atlassian's $10/month cloud hosting.

Additional Resources:

© 2022 • MatthewPick.com