繁体   English   中英

如何用问号重写 nginx URI

[英]How to rewrtite in nginx URI with a Question Mark

我正在尝试使用 nginx 重写带有问号的 URI? 我怎样才能逃避问号?

如果我使用没有“?”的测试 URI,则重写有效。 但是我有一个 404

    listen 80 default_server;
    listen [::]:80 default_server;

        root /var/www/html;

    index index.html index.htm index.nginx-debian.html;

    server_name example.com;

    #rewrite [^\/]+\/get\.php\?username=([^\&]+)&password=([^\&]+).*$ http://$host:8080/server/get_user_videolist?username=$1:password=$2 permanent;

    rewrite ^/get.phpusername=TEST123&password=SECRET123 http://$host:8080/server/get_user_chlist?username=TEST123:password=SECRET123;

    rewrite ^/get.php?Fusername=TEST123&password=SECRET123 http://$host:8080/server/get_user_chlist?username=TEST123:password=SECRET123;

}

我预期的 output 应该从第一个 URL 到第二个 URL

http://example.com/get.php?username=TEST123&password=SECRET123

->

http://example.com:8080/server/get_user_chlist?username=TEST123:password=Secret123

错误日志

2019/09/19 22:12:15 [error] 7059#7059: *183 open() "/var/www/html/get.php" failed (2: No such file or directory), client: *.*.*.*, server: example.com, request: "GET /get.php?username=TEST123&password=SECRET123 HTTP/1.1", host: "example.com"

我自己解决了http://nginx.org/en/docs/http/ngx_http_rewrite_module.html

location / {
if ($args ~* "/?username=([a-zA-Z0-9]+)&password=([a-zA-Z0-9]+)") {
        set $username $1;
        set $password $2;
        rewrite ^ http://$host:8080/server/get_user_chlist?username=$username:password=$password? last;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM