【问题标题】:NodeJS & Nginx Proxy not workingNodeJS 和 Nginx 代理不工作
【发布时间】:2016-06-23 03:31:37
【问题描述】:

我编写了一个基于sailsjs 的应用程序,部署在我的一个VPS 中。应用程序正在使用 pm2 以生产模式运行。我可以通过public_ip:1338访问,一切正常。

所以安装了 nginx,配置了 proxy_pass,安装了letsencrypt ssl。当我尝试访问域时,我看到的是使用 SSL 的 Nginx 默认页面,而不是 NodeJS (SailsJS) 应用程序。

这里是 nginx 配置文件

server {
    listen 80;
    server_name domain.net www.domain.net;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl spdy;
    listen [::]:443 ssl spdy;

    ssl_certificate     /etc/letsencrypt/live/domain.net/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/domain.net/privkey.pem;

    server_name domain.net;

    location / {
        proxy_pass http://localhost:1338;
        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;
    }
}

我需要解决这个问题。你们能指导我解决这个问题吗?

【问题讨论】:

  • 我不认为它是重复的,因为我读过它,尝试过但失败了。我没有问现在是什么?,我提到了我想要什么我尝试了什么
  • 你是否在 nginx.conf 文件中包含 include /etc/nginx/sites-enabled/*;
  • 我已经把conf文件放到了/etc/nginx/conf.d目录下。

标签: node.js nginx


【解决方案1】:

我遇到了同样的问题。关注this guide,它奏效了。我确实需要在 nginx.conf 中包含include /etc/nginx/sites-enabled/* 才能使其工作。这是sites-enabled 文件夹中我的默认文件中的内容:

server {
    listen 443 ssl;
    server_name sitename.com www.sitename.com;

ssl_certificate /etc/letsencrypt/live/sitename.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sitename.com/privkey.pem;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDH$
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;

location ~ /.well-known {
     allow all;
}


location / {
    proxy_pass http://localhost:8080;
    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 sitename.com www.sitename.com;
    return 301 https://$host$request_uri;
}

【讨论】:

    猜你喜欢
    • 2019-09-27
    • 2017-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多