【问题标题】:Changing nginx config to accommodate nodejs how to?更改 nginx 配置以适应 nodejs 如何?
【发布时间】:2017-06-18 13:03:18
【问题描述】:

我有一个子域的nging php 配置。我也安装了node 5pm2

我想知道如何修改配置以将 test.domain.com 代理到节点端口 8080 或 3000。我一直在尝试 few things,但没有成功。

我希望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;
    }
}

【问题讨论】:

    标签: javascript node.js nginx proxy


    【解决方案1】:

    尝试以下 nginx 配置。并将其放入/etc/nginx/servers。您应该能够代理传递到节点服务器。确保节点服务器已启动并正在运行。

    server {
        listen      80;
        server_name test.domain.com;  
    
        location / {
            proxy_pass http://localhost:8080;
            proxy_set_header Host $host;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-03-10
      • 1970-01-01
      • 2018-01-28
      • 2015-06-07
      • 1970-01-01
      • 2021-12-08
      • 1970-01-01
      • 2016-11-16
      • 2015-06-10
      相关资源
      最近更新 更多