Mapping ports and sub-domains with NGINX reverse proxy
This is simple step by step guide to setup a Reverse Proxy using nginx in Linux. Installing step takes Ubuntu for example, but you can go to nginx page for other platform install guide.
Intro
For simplicity, let assume our situation like this:
- We have a domain example.com.
- We have a server, running Ubuntu for example.
- This server running 2 web pages, in separate HTTP ports: 1111 and 2222.
- We want to use root domain example.com to serve web page in port 1111.
- We want to add a blog to sub domain blog.example.com, which serve web page in port 2222.
In short, we want to forward visitor like this:
- example.com -> localhost:1111
- blog.example.com -> localhost:2222
Install
Here is install for Ubuntu with apt tool. For other OS, you can go to nginx home page for detail.
Declare sites
We declare rules for proxy by create 2 files in /etc/nginx/sites-available/
For root domain example.com:
For sub domain blog.example.com:
Enable sites
Link your sites configuration from folder sites-available
to folder sites-enabled
: