nginx proxy_pass:
proxy_pass 最后带斜杠/直接访问转发地址
proxy_pass 最后不带斜杠/,将location地址拼接到转发地址之后访问
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8888;
server_name localhost 127.0.0.1;
#直接访问本地django8000服务
location /test {
proxy_pass http://127.0.0.1:8000/;
}
#拼接test1访问8000端口404
location /test1 {
proxy_pass http://127.0.0.1:8000;
}
#拼接admin后访问django
location /admin {
proxy_pass http://127.0.0.1:8000;
}
#直接转发到qq主页
location /test2 {
proxy_pass https://www.qq.com/;
}
#goole 502 原因暂定
location /test3 {
proxy_pass https://www.google.com/;
}
#将wang之后的部分传给百度wd
location /wang {
proxy_pass https://www.baidu.com/s?wd=;
}
#正则匹配,将reg之后的部分传递给wd
location ~ ^/reg/(.*)$ {
proxy_pass https://www.baidu.com/s?wd=$1;
}
#配置错误:
#"proxy_pass" cannot have URI part in location given by regular expression, or inside named location
location ~ ^/reg1/(.*)$ {
proxy_pass https://www.baidu.com/s?wd=;
}
}
rewrite demo
location /test {
rewrite ^/test(.*)$ http://www.baidu.com/s?wd=$1;
}
location /test1 {
rewrite ^/test(.*)$ /test;
#rewrite ^/test(.*)$ /test last;
}
location /test2 {
rewrite ^/test(.*)$ http://www.qq.com;
}
location /test3 {
rewrite ^/test(.*)$ /test break;
}
location /test4 {
#rewrite ^/test(.*)$ /test1 last;
rewrite ^/test(.*)$ /test1;
}
location /test5 {
rewrite ^/test5$ /cache/sethelp/index.html break;
proxy_pass https://www.baidu.com/;
}
location /test6 {
rewrite ^/test6(.*)$ /$1 break;
proxy_pass https://www.baidu.com/;
}
#http://localhost:8888/test7 500 Internal Server Error
location /test7 {
rewrite ^/test7(.*)$ $1 break;
proxy_pass https://www.baidu.com/s?wd=$1;
}
##http://localhost:8888/test8 正常
location /test8 {
rewrite ^/test8(.*)$ /$1 break;
proxy_pass https://www.baidu.com/s?wd=$1;
}
}
}