Search code examples
phpnginxfastcgi

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


Situation:

I deployed my php project as a web server in the machine A, using nginx and fastcgi, and the config file is as following:

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;
}

so when I make a 'GET' request from my local machine as:

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

there will be json returned

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

However when I made the same request in the machine A, it just hanged there, and returned nothing. I also tried:

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

and

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

all not working. I don't know what is the problem.


Solution

  • You need to configure nginx to listen via localhost or 127.0.0.1 for it to work.

    See http://nginx.org/en/docs/http/ngx_http_core_module.html#listen for full instructions.

    You can add multiple listen statements eg:

    listen localhost;
    listen 127.0.0.1;
    

    Also see this for more detail: https://serverfault.com/questions/655067/is-it-possible-to-make-nginx-listen-to-different-ports