【问题标题】:How can I make a 'GET' request in the same server that php project deployed?如何在 php 项目部署的同一服务器中发出“GET”请求?
【发布时间】:2016-03-28 20:47:16
【问题描述】:

情况:

我在A机上部署了我的php项目作为web服务器,使用nginx和fastcgi,配置文件如下:

server {
    listen       80;
    server_name  alpha.kimi.com;
    index index.html index.htm index.php;
    root /alidata/www/;
    location ~ .*\.(php|php5)?$
    {
            #fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
    }

    location / {
        root   /www/admin/;
        index index.php;
        if (!-f $request_filename){
            rewrite ^/(.+)$ /index.php?$1& last;
        }
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
            expires 30d;
    }
    location ~ .*\.(js|css)?$
    {
            expires 1h;
    }


    access_log  /data/log/nginx/access/output.log;
    error_log   /data/log/nginx/access/error.log;
}

所以当我从本地机器发出“GET”请求时:

curl http://alpha.kimi.com/app/redirect/taskpush?build=10&gcdata=1

会有json返回

{"res":200,"msg":"success","extra":[]}

但是,当我在机器 A 上发出相同的请求时,它就挂在那里,什么也没返回。我也试过了:

curl http://localhost/app/redirect/taskpush?build=10&gcdata=1

curl http://localhost:9000/app/redirect/taskpush?build=10&gcdata=1

一切都不起作用。我不知道是什么问题。

【问题讨论】:

标签: php nginx fastcgi


【解决方案1】:

您需要将 nginx 配置为通过 localhost 或 127.0.0.1 进行侦听才能正常工作。

有关完整说明,请参阅 http://nginx.org/en/docs/http/ngx_http_core_module.html#listen

您可以添加多个监听语句,例如:

listen localhost;
listen 127.0.0.1;

更多详情另见:https://serverfault.com/questions/655067/is-it-possible-to-make-nginx-listen-to-different-ports

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-27
    • 1970-01-01
    • 1970-01-01
    • 2022-10-25
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 2016-01-04
    相关资源
    最近更新 更多