Nginx通过配置resolver解决proxy_pass中使用变量参数作为转发地址

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

比如我的url为:localhost/redirect/2?destip=wiki.jikexueyuan.com

我的nginx.conf配置:

server {
        listen       80;
        server_name  localhost;
        resolver 1.2.4.8;#这个就是做域名解析的,如果你的地址直接是ip则可以不需要这个配置

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        
        location  /redirect/1 {
            rewrite ^(.*)$ http://$arg_dest-ip:$arg_dest-port/$arg_uri/$arg_media-type/$arg_media-id?token=$arg_token?;
        }
        
        location  /redirect/2 {
            proxy_pass http://$arg_destip/;#$arg_destip就是url中带的参数destip的值
            #proxy_pass $arg_destip;
            #proxy_set_header Data $arg_destip;
            #echo $arg_destip;
            #proxy_set_header Data $arg_h-Date;
            #proxy_set_header Authorization $arg_h-Authorization;
            #proxy_set_header Content-Type $arg_h-Content-Type;
            #proxy_set_header Content-Length $content_length;
        }

转载于:https://my.oschina.net/ffse54s/blog/1499308

你可能感兴趣的:(Nginx通过配置resolver解决proxy_pass中使用变量参数作为转发地址)