简体   繁体   English

更改nginx配置以适应nodejs怎么办?

[英]Changing nginx config to accommodate nodejs how to?

I have a nging php config for a subdomain. 我有一个子网域的nging php配置。 i also have node 5 installed and pm2 我也安装了node 5pm2

I'm wondering how to modify the config to have test.domain.com proxy to node port 8080 or 3000. I've been trying a few things with no success. 我想知道如何修改配置以将test.domain.com代理设置为节点端口8080或3000。我一直在尝试一些成功的尝试。

I would like test.domain.com to point to the node server rather then to /usr/share/nginx/html/test 我希望test.domain.com指向节点服务器,而不是/usr/share/nginx/html/test

server {
    listen      80;
    server_name test.domain.com;
    set         $root_path '/usr/share/nginx/html/test';
    root        $root_path;

    access_log  /var/log/nginx/test-access.log;
    error_log   /var/log/nginx/test-error.log error;

    index index.php index.html index.htm;

    try_files $uri $uri/ @rewrite;

    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    location ~ \.php {
        # try_files    $uri =404;

        fastcgi_index  index.php;
        fastcgi_pass   127.0.0.1:9000;

        include fastcgi_params;
        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param APPLICATION_ENV "testing";
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
    }

    location ~ /\.ht {
        deny all;
    }
}

Try following nginx config. 尝试以下nginx配置。 And put it in /etc/nginx/servers . 并将其放在/etc/nginx/servers You should be able to proxy pass to node server. 您应该能够代理传递给节点服务器。 Ensure node server is up and running. 确保节点服务器已启动并正在运行。

server {
    listen      80;
    server_name test.domain.com;  

    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM