Hosting Multiple Apps With Nginx Rewrite Rules

Image credit: Unsplash

Suppose you plan on hosting multiple API endpoints on one domain, make it api.your-domain.com, one way to do it is to put each endpoint under a distinctive path, each one would look like:

    https://api.your-domain.com/myapp1/
Tunneling through a Nginx reverse proxy

Configure a reverse proxy such as Nginx and set up rewrite rules can get it done quickly.

See below my example:

Depending on your Linux distro and Nginx, most would need to put the conf file under /etc/nginx/sites-available/ directory and create a symbol link in /etc/nginx/sites-enabled/.

Restart nginx service by sudo systemctl restart nginx ; and it’s working!


Related