nginx可以请求站外地址么?
伊谢尔伦
伊谢尔伦 2017-05-16 17:24:30
[Linux讨论组]

我是 nginx 新手,试了多次 proxy_pass 的跳转都无法跳转到站外。nginx 可以请求站外链接么?

目前有一个外部的API接口地址:http://122.23.21.212/api/v2?args=others&argc=4

现在我想实现这样的功能:

当我访问 http://localhost/myapi?args=others&args=4 的时候,其实 nginx 在内部是去访问 http://122.23.21.212/api/v2?args=others&argc=4 这个接口,请问这个需要怎么样进行配置呢?

shellserver {

    ...

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

    ...
}

各位帮忙看看,谢谢

伊谢尔伦
伊谢尔伦

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

全部回复(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=

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号