Practical case of Nginx reverse proxy configuration
1. Achieve goals
Reverse proxy, for example, is that multiple domain name A records are the same server and access port 80 at the same time, but the server can automatically assign it to local ports such as 8000, 8080, etc.
Example: Access imustctf.top
will point to 127.0.0.1:8000
the port of the domain name A record IP
2. Practical operation begins
Currently there are two static front-end sites under the WWW directory
First configure the seelgo project, which is just a front-end page managed by php, without an additional back-end server, so the configuration is very simple:
server {
listen 88;
server_name seelgo;
# 指定前端项目所在的位置
location / {
root D:/CStools/phpstudy_pro/WWW/seelgo;
index index.html index.htm;
}
}
Try accessing port 88:
Then configure the secureqr project, which is a project with a front-end and back-end separation architecture. There is an additional back-end server, so it needs to be configured location
for forwarding:
server {
listen 8689;
server_name secureqr;
# 指定前端项目所在的位置
location / {
root D:/CStools/phpstudy_pro/WWW/secureqr;
index index.html index.htm;
}
location /api/ {
# 开启重写日志记录,这个会记录在error.log里面,级别为notice
rewrite_log on;
# 重写规则,可根据实际情况调整。
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:8589;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Try accessing port 8689: