2017-08-04 1 views
0

私はこのプロキシを自分のnginx設定で受け取りました。ルートを1つのアドレスにプロキシし、残りをnginxの他のアドレスにプロキシすることはできますか?

location /content { 
proxy_set_header Host $proxy_host; 
proxy_pass $address1; 
if ($request_method = 'OPTIONS') { 
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; 
    add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; 
    add_header 'Access-Control-Max-Age' 1728000; 
    add_header 'Content-Type' 'text/plain charset=UTF-8'; 
    add_header 'Content-Length' 0; 
    return 204; 
} 
if ($request_method = 'POST') { 
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; 
    add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; 
} 
if ($request_method = 'GET') { 
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; 
    add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; 
} 

}

私は$address1から/contentをproxy_passしたいと思いますが、私は他のどの/content/something_else$address2にproxy_passしたいと思いますがnginxの中で、この可能ですか?例えば

私は$address1/contentをproxy_passしたいと思いますが、私は$address2に、他の/content/something_elseをproxy_passしたいと思い、私はhttp://www.example.com/content?some_other_param=valueをヒットした場合、http://www.content.comに転送されるだろうが、私はhttp://www.example.com/content/article?some_param=valueをヒットした場合、それはhttp://www.different_content.com

+0

私の答えが質問に答えるなら、+1してください。そうでない場合は、何が欠けているか教えてください。ありがとう。 – cnst

答えて

1

を打つだろうこれはnginxで可能ですか?

はい。 location = /content w/$address1location /content w/$address2を使用できます。これは、特に2つのアドレスがそれほど多くを共有しない場合には、好ましい構成となる。

+0

ありがとうございました。私はそれを試みます。 – toy

関連する問題