nginx简单配置

通过
http://192.168.0.100:10003/AimDir
访问
http://192.168.0.100:10006/training-match/AimDir

找到nginx的配置文件,例如/etc/nginx/nginx.conf

# 先添加upstream 用于负载均衡
upstream upstreamName {
    # upstreamName服务IP和端口
    server 192.168.0.100:10006;
}

然后在http模块内添加server模块

server {
    listen 10003;
    server_name 192.168.0.100;

    location /AimDir {
        proxy_pass http://192.168.0.100:10006/redundantDir/AimDir;
    }
}

或者直接把/后面的内容去掉也行
server {
    listen 10003;
    server_name localhost;

    location / {
        proxy_pass http://upstreamName/redundantDir/;
    }
}

解析:
这个模块的意思是:

将http://{server_name}:{listen}{location}转发为proxy_pass
即http://192.168.0.100:10003/xxx
转发为http://192.168.0.100:10006/training-match/xxx;

例如:在浏览器发送http://192.168.0.100:10003/test.html后,经nginx转发为http://192.168.0.100:10006/redundantDir/test.html去对应的服务器取数据,然后再返回给发送http://192.168.0.100:10003/test.html请求的人。

原文地址:https://www.cnblogs.com/czp2016/p/15336626.html