nginx 由以下几部分组成

proxy_pass指令可以根据规则代理到proxy_pass后的url地址

server_name 用于定义哪些url使用此规则
将gulimaill.com 下所有请求进行代理
负载均衡语法如下 upstream定义于在均衡服务器 proxy_pass使用负载均衡服务器
可以使用此方法代理网关
http {
upstream myapp1 {
server srv1.example.com;
server srv2.example.com;
server srv3.example.com;
}
server {
listen 80;
location / {
proxy_pass http://myapp1;
}
} upstream gulimall {
server 192.168.1.7:10001;
}
location / {
proxy_set_header Host $host;
# proxy_pass http://192.168.1.7:10000;
proxy_pass http://gulimall;
}然后配置gateway
当url为***.gulimaill.com的话 跳转至商品服务

此处有坑 因为nginx不会携带Host请求头 所有还得添加proxy_set_header Host $host;配置
以上就是nginx反向代理怎么办的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号