Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Node.js设置获取内部服务器错误(500)以使用HTTPS_Node.js_.htaccess_Https - Fatal编程技术网

使用Node.js设置获取内部服务器错误(500)以使用HTTPS

使用Node.js设置获取内部服务器错误(500)以使用HTTPS,node.js,.htaccess,https,Node.js,.htaccess,Https,我使用的是一个非常简单的服务器脚本 const https = require('https'); const fs = require('fs'); var options = options = { key: fs.readFileSync(__dirname+'/certs/private_key.pem'), cert: fs.readFileSync(__dirname+'/certs/my_cert.crt'), ca: fs.readFileSync(__

我使用的是一个非常简单的服务器脚本

const https = require('https');
const fs = require('fs');

var options = options = {
    key: fs.readFileSync(__dirname+'/certs/private_key.pem'),
    cert: fs.readFileSync(__dirname+'/certs/my_cert.crt'),
    ca: fs.readFileSync(__dirname+'/certs/my_bundle.ca-bundle'),
}

https.createServer(options, (req, res) => {
res.writeHead(200);
res.end('hello world\n');
}).listen(3000,'example.com');
这个例子取自

我的.htaccess看起来像这样

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com:3000/$1 [L,P,QSA]
目标是使用HTTPS将所有流量重定向到服务器。当我执行命令时

node server.js
没有错误,服务器正在侦听。当我尝试使用浏览器连接时

https://example.com
我遇到了一个内部服务器错误,我无法确定问题可能是什么,因为我无法确定如何从node.js获取任何日志


如果我将服务器设置为通过常规HTTP进行侦听,并将.htaccess重写规则设置为通过常规HTTP重定向到站点,则可以正常工作。我一辈子都搞不清楚我做错了什么,因为当我用证书在本地测试服务器时,它似乎在HTTPS上工作正常(即,即使浏览器说证书无效)。知道问题是什么吗?不管怎样,要从node.js获取相关日志?

我想出了一个解决方案,看起来很有效,但请记住我是一个noob

只是一些简短的背景

  • Godaddy目前正在托管我的文件(我的计划是最便宜的)
我没有尝试将node.js设置为HTTPS服务器,而是将其作为常规HTTP服务器运行。对于SSL功能,我使用CPanel中名为“SSL/TLS”的GoDaddy配置工具安装证书(私钥、捆绑包等)。完成后,我可以键入:

https://example.com
连接显示为安全的。为了在常规的node.js HTTP服务器上实现这一点,我必须修改primary.htaccess文件中的重写规则。即

RewriteEngine on
RewriteCond %{HTTPS} off                                   # To ensure no redirect loop
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]        # Redirect to the secure site
RewriteRule (.*) http://example.com:3000/$1 [L,P,QSA]      # Internally, however, pass all request to the regular HTTP node.js server listening on port 3000
现在我可以在浏览器中键入任何URL(即www.example.com,example.com),它们都会重定向到,并且所有网站数据都会根据浏览器通过安全连接正常获取