如果存在参数,则代理到后端

时间:2017-09-08 14:32:44

标签: nginx

Nginx配置

server {
        listen 80;

        server_name site-frontend.com;
        root /home/jashka/PhpstormProjects/site-frontend;
        index index.html;

        location ~* sharing {
                proxy_pass http://localhost:8000/social-sharing;
        }

        location / {
                try_files $uri$args $uri$args/ index.html;
        }

        error_page 404 /index.html;
}

错误:

nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/conf.d/site-frontend.conf:28

如何解决此错误或重写配置?

1 个答案:

答案 0 :(得分:0)

修改-1

我已对此进行了测试,它适用于两个示例网址

$ curl -I vm/avbc/sharing/test/
HTTP/1.1 301 Moved Permanently
Server: openresty/1.11.2.2
Date: Fri, 08 Sep 2017 15:32:51 GMT
Content-Type: text/html
Content-Length: 191
Location: http://vm/social-sharing
Connection: keep-alive

$ curl -I "vm/avbc/?sharing=yes"
HTTP/1.1 301 Moved Permanently
Server: openresty/1.11.2.2
Date: Fri, 08 Sep 2017 15:33:09 GMT
Content-Type: text/html
Content-Length: 191
Location: http://vm/social-sharing
Connection: keep-alive

测试显示正确的输出

server { 
listen 80; 

server_name getresto-frontend.com; 

root /home/jashka/PhpstormProjects/getresto-frontend; 
index index.html; 


sendfile off; 

location / { 
error_page 409 = @social; 

if ($arg_sharing) { 
return 409; 
} 

location ~ .*/sharing/?.* { 
return 409; 
} 

编辑-2(2017年9月9日)

如果您不希望发生重定向,那么下面的配置应该可以正常工作

struct arrayStruct {
    bool    someParam;
};

struct someStruct {
    bool    topParam;

    QVector< arrayStruct >    arrayOfStructs;
};