You may have different reason to setup reverse proxy locally on your Mac. But in my case I worked with WebRTC. Our project relying on subdomains and we use lvh.me to easily implement them locally. So we have something like: subdomain.lvh.me:3000
which resolved to localhost:3000
. It works fine except WebRTC because Chrome required HTTPS for WebRTC and allow to use HTTP only on localhost
. To work around it I decided to launch reverse proxy with nginx
which will resolve localhost
requests on specific port to our lvh subdomain.
Steps to setup local reverse proxy with nginx
Before running this commands make sure you have Homebrew installed.
- Install
nginx
brew install nginx
- Setup launchd to start nginx on login and now
brew services start nginx
- Change
/usr/local/etc/nginx/nginx.conf
to following
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
server_name localhost;
location / {
proxy_pass http://YOUR_DOMAIN:YOUR_PORT;
}
}
}
Done. Now you can go to localhost:8080
and it will be proxied to http://YOUR_DOMAIN:YOUR_PORT
. You also may want to change proxy port in nginx
config.