Can nginx request an off-site address?
伊谢尔伦
伊谢尔伦 2017-05-16 17:24:30
0
1
489

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?

shellserver {

    ...

    location /myapi {
        proxy_pass http://122.23.21.212/api/v2?$request_uri;
    }

    ...
}

Please help me, thank you

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
刘奇
    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=

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template