在ubuntu 14.04上的同一台服务器上运行Nginx上的Node.js和PHP

时间:2015-10-20 06:51:57

标签: php node.js nginx

我已经在内置node.js的nginx上运行应用程序,现在我必须使用php创建另一个应用程序,也应该在同一台机器上的nginx上运行,如果我调用“127.0.0.1:3001”那么节点应用程序应该运行,如果我调用“127.0.0.1:3002”,那么php应该调用。

这是我的nignx配置文件(/ etc / nginx / site-available / default)

upstream app_stat {
    server 127.0.0.1:3001;
    keepalive 80;
}

#upstream app_php {
#    server 127.0.0.1:3002;
#    keepalive 80;
#}

server {
    listen 80 default_server;
    #listen [::]:80 default_server ipv6only=on;

    root /home/manish/workspace/statistics;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

        # static resources
        location ~ ^/(robots.txt|humans.txt|favicon.ico) {
                    root /home/manish/workspace/statistics;
                    access_log on;
                    expires max;
        }

    location ~ /js/(.*) {
            add_header X-debug-message "A static file was served by pushstate";

            proxy_redirect off;
            proxy_set_header   X-Real-IP         $remote_addr;
            proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   Host              $http_host;
            proxy_set_header   X-NginX-Proxy     true;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_pass         http://app_stat;
        }

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        # try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules

            if ($http_user_agent ~ (Googlebot|google|bing|yandex|msnbot|AltaVista|DuckDuckBot) ) {
               return 403;
            }

                add_header X-debug-message $http_accept;
             # break;
                proxy_redirect off;
                proxy_set_header   X-Real-IP         $remote_addr;
                proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Proto $scheme;
                proxy_set_header   Host              $http_host;
                proxy_set_header   X-NginX-Proxy     true;

                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";

                proxy_pass         http://app_stat;
    }

}

server {
    listen 80;
    listen [::]:80 ipv6only=on;

    server_name localhost;

    root /var/www;
    index index.php index.htm index.html;

#   location / {
#       try_files $uri $uri/ =404;
#       proxy_pass http:localhost:3002;
#       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#           proxy_set_header Host $http_host;
#           proxy_set_header X-Forwarded-Proto $scheme;
#           proxy_buffering off;
#   }

    location ~/.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:3002;
            fastcgi_index index.html;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params; 
    }
}

现在,当我启动时,nginx服务启动,并运行127.0.0.1:3001(节点应用程序),运行正常,但是当我调用127.0.0.1:3002(php)时,发生ERR_CONNECTION_REFUSED错误,为什么?< / p>

0 个答案:

没有答案