文章目录
Nginx proxy_pass 转发规则配置
/api1/
>> http://ip:port
http://localhost/api1/xxx
>> http://localhost:8080/api1/xxx
server {
listen 80;
location /api1/ {
proxy_pass http://localhost:8080;
}
}
/api1/
>> http://ip:port/
http://localhost/api2/xxx
>> http://localhost:8080/xxx
server {
<!--listen 80;-->
location /api2/ {
proxy_pass http://localhost:8080/;
}
}
/api3
>> http://ip:port
http://localhost/api3/xxx
>> http://localhost:8080/api3/xxx
server {
listen 80;
location /api3 {
proxy_pass http://localhost:8080;
}
}
/api4
>> http://ip:port/
http://localhost/api4/xxx
>> http://localhost:8080//xxx
注意:这里是双斜线
8080//xxx
,不知道能否访问
server {
listen 80;
location /api4 {
proxy_pass http://localhost:8080/;
}
}
/api5/
>> http://ip:port/haha
http://localhost/api5/xxx
>> http://localhost:8080/hahaxxx
注意:这里
hahaxxx
之间没有斜杆
server {
listen 80;
location /api5/ {
proxy_pass http://localhost:8080/haha;
}
}
/api6/
>> http://ip:port/haha/
http://localhost/api6/xxx
>> http://localhost:8080/haha/xxx
注意和
api5
的区别
server {
listen 80;
location /api6/ {
proxy_pass http://localhost:8080/haha/;
}
}
/api7
>> http://ip:port/haha
http://localhost/api7/xxx
>> http://localhost:8080/haha/xxx
server {
listen 80;
location /api7 {
proxy_pass http://localhost:8080/haha;
}
}
/api8
>> http://ip:port/haha/
http://localhost/api8/xxx
>> http://localhost:8080/haha//xxx
注意:
haha//xxx
这个双斜杆
server {
listen 80;
location /api8 {
proxy_pass http://localhost:8080/haha/;
}
}