nginx's proxy_pass and proxy_pass use demo

nginx proxy_pass:

proxy_pass final with a slash / direct access to the forwarding address

After last proxy_pass without slash /, the splice location address access to the forwarding address

    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;
        }
         }

}

 

Published 115 original articles · won praise 34 · views 90000 +

Guess you like

Origin blog.csdn.net/u011519550/article/details/103896510