dongzhan9100 2015-10-20 06:51
浏览 34

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

I have already running app on nginx built in node.js, Now I have to create another app using php, should also run on nginx on same machine, like If I call "127.0.0.1:3001" then node application should run and if I call "127.0.0.1:3002", then php application should call.

Here is my nignx config file (/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; 
    }
}

Now When I start, nginx service, it started, and run 127.0.0.1:3001 (node app), it's running OK, but when I call 127.0.0.1:3002 (php), ERR_CONNECTION_REFUSED error occured, why?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作