【发布时间】:2017-10-21 13:15:42
【问题描述】:
我们将 Apache Server 和 NodeJs (Express) 组合用于网站。 没有 SSL,Apache 过去监听 80 端口,Nodejs 监听 8080 端口。
现在,我正在网站上安装 SSL。 Apache 设置为监听端口 443。我试图让 Nodejs 监听端口 8443、3333 等 - 将 AWS 安全组设置为端口的“自定义 TCP”。问题是我没有收到来自 Nodejs 服务器的任何响应。我的直觉是问题出在 EC2 安全组设置上,但无法真正指出确切的问题。
为 Nodejs 创建的服务器如下:
var https = require('https');
var fs = require('fs');
...
...
var https_options = {
ca: fs.readFileSync ("/path/to/cabundle.ca-bundle", "utf8"),
key: fs.readFileSync("/path/to/sslkey.key", "utf8"),
cert: fs.readFileSync("/path/to/certificate.crt", "utf8")
};
var app = express();
var server = https.createServer(https_options, app);
....
....
server.listen(8443 or 3333);
启动服务器不会导致任何错误。 浏览器,从我调用 Nodejs 服务器的地方,没有显示任何错误。
感谢任何见解。
在 Arif 指出这可以通过 Apache 设置解决后,我在
处添加了 Virtualhost 设置/etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName www.example.com
Redirect permanent / https://www.example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/mysite
Servername www.example.com
SSLEngine on
SSLCertificateKeyFile /path/to/sslkey.key
SSLCertificateFile /path/to/certificate.crt
SSLCertificateChainFile /path/to/cabundle.ca-bundle
<Directory /var/www/html/mysite>
AllowOverride All
Options FollowSymlinks
</Directory>
</Virtualhost>
客户端请求发送到https://www.example.com:8443
【问题讨论】:
-
您必须使用
https来发出https://www.example.com:8443的请求。如果您正在请求https://www.example.com:8443,则没有 apache 的角色。 -
你可以向 EC2 中的 nodejs 服务器 (
curl -Ik https://127.0.0.1:8443) 发出请求吗?你之前有没有在iptables里加过规则? -
@ArifKhan 对不起,我的错。它是 https://...
-
@ronald8192 我得到以下信息:HTTP/1.1 404 Not Found X-Powered-By: Express Content-Security-Policy: default-src 'self' X-Content-Type-Options: nosniff Content -类型:文本/html; charset=utf-8 内容长度:140 日期:星期六,2017 年 10 月 21 日 23:13:59 GMT 连接:保持活动............ ..不,我从来没有这样做过。
-
@Sam11 如果你没有被找到,这意味着你没有实现/ GET 路线
标签: node.js express amazon-ec2 https