0

我整个早上都在努力让这个工作。我在 Linode 托管的 CentOS 上全新安装了 Nginx 和 Nodejs。

我有一个从 root 或 public_html 运行的 CodeIgniter 的工作安装。在 public_html 中,我有一个名为 /nodejs 的目录,我试图从中运行节点服务器。

我收到 502 Bad Gateway 错误...

这在我的 error.log 文件中。

2013/10/23 19:21:07 [error] 2614#0: *1 connect() failed (111: Connection refused) while     connecting to upstream, client: xx.x.xx.xxx, server: mydomain.com, request: "GET /nodejs/index.html HTTP/1.1", upstream: "http://127.0.0.1:3031/nodejs/index.html", host: "mydomain.com"

这是我的 /opt/nginx/conf/nginx.conf

worker_processes 1;

events {
    worker_connections  1024;
}

http {
    upstream app_nodejs {
        server 127.0.0.1:3031;
    }

include mime.types;
default_type  application/octet-stream;
sendfile on;

server {
    server_name mydomain.com;
    large_client_header_buffers 4 16k;
    access_log /srv/www/mydomain.com/logs/access.log;
    error_log /srv/www/mydomain.com/logs/error.log;
    root /srv/www/mydomain.com/public_html;
    index index.php index.html;

    location ~* ^/(css|fonts)/(.+)$ {
        root /srv/www/mydomain.com/public_html/assets;
    }

    location / {
        try_files $uri $uri/ @ci;
    }

    location ~* /nodejs {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://app_nodejs;
        proxy_redirect off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    location @ci {
        if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php/$1 last;
            break;
        }
    }

    location ~ \.php {
        include fastcgi_params;
        set $php_root /srv/www/mydomain.com/public_html;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param REQUEST_URI $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME /srv/www/mydomain.com/public_html$fastcgi_script_name;
       fastcgi_pass 127.0.0.1:9000;
       fastcgi_index index.php;
    }
}
}

任何帮助将不胜感激。谢谢

4

1 回答 1

1

我不是 nginx 专家,但看起来你在那里的某个地方错过了一个结束的 '}'。http 部分永远不会关闭。

于 2013-10-24T00:52:30.860 回答