当前nginx服务器IP为192.168.231.128。
针对一个IP,可以通过路径跳转到多个项目,server配置如下:
server {
listen 8081;
server_name 192.168.231.128;
location / {
proxy_pass http://localhost:8080;
}
location /txffc {
proxy_pass http://localhost:8082;
}
}
proxy_pass最后待斜杠和不带斜杠的区别如下:
location /txffc {
proxy_pass http://localhost:8082;
}
访问URL=http://192.168.231.128/txffc/common
指向的地址实际是:http://localhost:8082/txffc/common,
即nginx会把包括匹配到的内容都追加到proxy_pass地址后面。
location /txffc {
proxy_pass http://localhost:8082/;
}
访问URL=http://192.168.231.128/txffc/common
指向的地址实际是:http://localhost:8082/common,
即nginx不会把匹配到的内容追加到proxy_pass地址后面。
location 最后待斜杠和不带斜杠的区别如下:
location /txffc {
proxy_pass http://localhost:8082;
}
不带斜杠,可以匹配
http://192.168.231.128/txffc/common
http://192.168.231.128/txffcddd
http://192.168.231.128/txffcddd/aabc
location /txffc/ {
proxy_pass http://localhost:8082;
}
带斜杠,可以匹配
http://192.168.231.128/txffc/common
http://192.168.231.128/txffc/aabb
不能匹配
http://192.168.231.128/txffcddd