【发布时间】:2019-06-11 22:19:04
【问题描述】:
当我在浏览器中输入www.example.com:3000 时,我收到此错误(其中“example”是我的域的名称)
This site can't be reached - www.example.com took too long to respond.
我做过这些事情:
- 在我的 GoDaddy 共享帐户上安装了 node.js
- 创建了一个文件夹 ../public_html/testsite
- 在该文件夹中放置了两个文件:app.js 和 .htaccess。
- 启动网络服务器:node app.js
- 转到浏览器并输入我的域的 URL 和端口:
- 收到上面的错误信息
这个post 很有帮助,但我仍然无法让我的设置正常工作。
这两个文件在../public_html/testsite/
.htaccess
RewriteEngine on
RewriteRule ^index.html.var$ http://www.example.com:3000/$1 [L,P,QSA]
RewriteRule (.*) http://www.example.com:3000/$1 [P,L]
注意:index.html 是您访问此处时通常加载的文件
app.js:
const http = require('http');
const hostname= '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('NodeJS server running on Shared Hosting\n');
});
server.listen(port, hostname, () => {
console.log('Server running at http://' + hostname + ':' + port + '/');
});
启动网络服务器:
> cd ../public_html/testsite
> node app.js
Server running at http://127.0.0.1:3000
在浏览器中,我输入:
www.example.com:3000
我希望在浏览器中看到
NodeJS server running on Shared Hosting
问题:
- 我应该在
.htaccess中使用我自己的godaddy 域地址作为主机名还是应该是localhost? - 是否将
www.example.com:3000(在浏览器中)重定向到http://localhost:3000(在GoDaddy 服务器上)? - 我尝试了各种排列方式(使用我的 IP 地址或域名、不同的端口号等)
- 我想我已经接近了,但需要一些想法来尝试!
【问题讨论】:
-
您链接的说明将两个文件直接放在
public_html文件夹中。我想你应该试着把它们移到那里。我也认为你应该去 example.com,没有端口 3000。如果你去example.com/testsite,你现在拥有的东西可以工作
标签: javascript node.js shared-hosting