I am new to nginx. I have tried proxy_pass many times but cannot jump outside the site. Can nginx request external links?
Currently there is an external API interface address: http://122.23.21.212/api/v2?args=others&argc=4
Now I want to implement this function:
When I access http://localhost/myapi?args=others&args=4, nginx actually accesses the http://122.23.21.212/api/v2?args=others&argc=4 interface internally. Please tell me. How does this need to be configured?
shell
server { ... location /myapi { proxy_pass http://122.23.21.212/api/v2?$request_uri; } ... }
Please help me, thank you
怪我咯2017-05-16 17:26:30
server {
...
location /myapi {
if ( $query_string ~ "(args=others&args=4)$") {
rewrite ^/ http://122.23.21.212/api/v2;
}
}
...
}
[fifilyu@archlinux ~]$ curl -I 'http://localhost/myapi?args=others&args=4'
HTTP/1.1 302 Moved Temporarily
Server: nginx/1.8.0
Date: Wed, 06 May 2015 01:04:15 GMT
Content-Type: text/html
Content-Length: 160
Connection: keep-alive
Location: http://122.23.21.212/api/v2?args=others&args=