Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nginx proxy\u传递所有url参数_Nginx - Fatal编程技术网

Nginx proxy\u传递所有url参数

Nginx proxy\u传递所有url参数,nginx,Nginx,我想代理如下请求: http://myproxy.com/api/folder1/result1?test=1,http://myproxy.com/api/folder3447/something?var=one 到等效目的地:http://destination.com/folder1/result1?test=1和http://destination.com/folder3447/something?var=one,实际上只会更改域,并保留所有子文件夹和参数 配置中的位置如下所示: loc

我想代理如下请求:
http://myproxy.com/api/folder1/result1?test=1

http://myproxy.com/api/folder3447/something?var=one

到等效目的地:
http://destination.com/folder1/result1?test=1
http://destination.com/folder3447/something?var=one
,实际上只会更改域,并保留所有子文件夹和参数

配置中的位置如下所示:

location ~* ^/api/(.*) {
    proxy_pass http://destination.com/$1$is_args$args;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    #proxy_set_header  Host $http_host;
  }

您应该能够稍微简化配置:

location /api/ {
    // Note the slash at end, which with the above location block
    // will replace "/api/" with "/". This will not work with regex
    // locations
    proxy_pass http://destination.com/;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
}

您应该能够稍微简化配置:

location /api/ {
    // Note the slash at end, which with the above location block
    // will replace "/api/" with "/". This will not work with regex
    // locations
    proxy_pass http://destination.com/;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
}