云端服务器上部署了 项目1 项目2 项目3 项目4
一般的操作是: 项目2 项目3 项目4不对外,只有项目1对项目2 3 4的访问
项目1是可以对外的访问
所以在nginx上配置了一个 项目1的/*** 加后缀的方式 来访问 项目2 3 4
这就是反向代理。
正向代理:
也就是项目2 3 4 也是作为可以对外访问的渠道,让别人去调用。
引申:
反向代理的nginx写法:
server {
listen 8074;
server_name ***.***.***.***;
location / {
root html/huohua;
index index.html;
try_files $uri $uri/ /index.html;
}
location /api/{
proxy_pass http://192.168.3.215:8001/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
如果报错:
Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
特别注意加上斜杠: