使用NginX在Digital Ocean上托管多个node.js应用程序

时间:2014-08-31 17:33:35

标签: node.js nginx digital-ocean

我按照本指南为我的节点应用设置了反向代理 - https://www.digitalocean.com/community/tutorials/how-to-host-multiple-node-js-applications-on-a-single-vps-with-nginx-forever-and-crontab

它的要点是包含此配置

server {
    listen 80;

    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

这似乎适用于根位置 - /,但在添加自定义文件夹路径时失败。像这样的东西 -

server {
    listen 80;

    server_name your-domain.com;

    location /test/ {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

}

我的目标是使用example.com/test/导航到我的网站,以便我可以列出多个程序路径。我从chrome获得的错误无法获取example.com/test /

1 个答案:

答案 0 :(得分:1)

每个应用程序中proxy_pass的端口需要不同。您也可以参考此数字海洋article

 server {
        listen 80;

server_name your-domain.com;

location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

location /test {
    proxy_pass http://localhost:3009;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}
}