nginx proxy_pass转发规则配置
转发来的,转发哪里忘记了。
好久没有操作nginx了,一些规则还是很容易搞错,这边做个记录。
1. http://localhost/api1/xxx->http://localhost:8080/api1/xxx
server {
listen 80;
location /api1/ {
proxy_pass http://localhost:8080;
}
}
2. http://localhost/api2/xxx->http://localhost:8080/xxx
server {
listen 80;
location /api2/ {
proxy_pass http://localhost:8080/;
}
}
3. http://localhost/api3/xxx->http://localhost:8080/api3/xxx
server {
listen 80;
location /api3 {
proxy_pass http://localhost:8080;
}
}
4. http://localhost/api4/xxx->http://localhost:8080//xxx
server {
listen 80;
location /api4 {
proxy_pass http://localhost:8080/;
}
}
注意这里是双斜线8080//xxx, 不知道能否访问,
5. http://localhost/api5/xxx->http://localhost:8080/hahaxxx
server {
listen 80;
location /api5/ {
proxy_pass http://localhost:8080/haha;
}
}
注意这里hahaxxx之间没有斜杆
6. http://localhost/api6/xxx->http://localhost:8080/haha/xxx
server {
listen 80;
location /api6/ {
proxy_pass http://localhost:8080/haha/;
}
}
注意和5的区别
7. http://localhost/api7/xxx->http://localhost:8080/haha/xxx
server {
listen 80;
location /api7 {
proxy_pass http://localhost:8080/haha;
}
}
8. http://localhost/api8/xxx->http://localhost:8080/haha//xxx
server {
listen 80;
location /api8 {
proxy_pass http://localhost:8080/haha/;
}
}
注意haha//xxx这个双斜杆