我正在尝试在 Nginx Ubuntu 17.04 上使用 SSL 的端口上设置 Node.js 生产应用程序。到目前为止,我已经SSL Nginx
启动并运行了服务器。
这是我的 Nginx 配置文件的样子:
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
if ($scheme != "https") {
return 301 https://$host$request_uri;
}
ssl_dhparam /etc/ssl/certs/dhparam.pem;
}
这就是我的 Node.js 应用程序的样子:
#content of index.js
'use strict';
const http = require('http');
http.createServer((req, res) => {
res.writeHead(200, {
'Content-Type': 'text/html; charset=utf-8',
});
res.write('<h1>I’m a Node app!</h1>');
res.end(3000, 'localhost')
}).listen();
console.log('http://example.com:3000/');
我想知道如何使用现有的 Nginx 配置将这个 Node.js 应用程序绑定到带有 SSL 的端口上。