Table of contents
Set up reverse proxy on local machine
See How to configure Reverse Proxy on Digital Ocean Droplet over Origin Server on AWS?
Pre-requisites
Prepare 2 separate server blocks on local machine.
Server 1 - origin server
Create a local nginx.conf
file. Click Here for config file sample
mkdir /users/A-name/nginx
vim nginx.conf
nginx -c /Users/A-name/Nginx/nginx.conf
# curl http://localhost:8888, check everything is good
Run php
locally
php -S localhost: 9999
# this will return 404
touch resp.txt
# content: "hello from php server"
php -S localhost: 9999 resp.txt
# curl http://localhost:9999
Server 2 - reverse proxy server
Add below in nginx location { … }
location /php {
proxy_pass http://localhost:9999/;
}
Then, check:
- curl http://localhost:8888/php
- outputs: Hello from php server
Server 1 - config file sample
# this is on local PC, not remote server
events { ... }
http {
server {
listen 8888;
location / {
return 200 "hello from Nginx\n";
}
location /php {
# add_header proxied nginx;
# adding custom header for this proxy, curl outputs "proxied:nginx"
proxy_set_header proxied nginx; #set the header on the proxy request
proxy_pass 'http://localhost:9999/';
}
location /nginx-org {
proxy_pass 'https://nginx.org/';
# must ends with '/'
}
}
}