我该如何制作';获取';在php项目部署的同一服务器中请求


How can I make a 'GET' request in the same server that php project deployed?

情况:

我使用nginx和fastcgi将我的php项目部署为机器a中的web服务器,配置文件如下:

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

所有这些都不起作用。我不知道问题出在哪里。

您需要将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