NodeJS& Nginx代理无法正常工作

时间:2016-06-23 03:31:38

标签: node.js nginx

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

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

这是nginx conf文件

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;
    }
}

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

1 个答案:

答案 0 :(得分:-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;
}