【问题标题】:getting server forbidden error in my browser在我的浏览器中出现服务器禁止错误
【发布时间】:2016-09-22 18:12:45
【问题描述】:

我刚刚开始探索 node.js。在我的 Windows 服务器上安装了 msi 文件。我下面的代码在命令窗口中返回了我的预期输出

var http = require("http");

http.createServer(function (request, response) {

// Send the HTTP header 
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});

// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8081);

// Console will print the message
console.log('Server running at `http://127.0.0.1:8081/`');

但是当我在浏览器中输入http://127.0.0.1:8081/ 时,我没有得到任何输出。当我看到控制台时,我得到以下错误

Failed to load resource: the server responded with a status of 403 (Forbidden)

我错了什么以及如何解决?我正在关注这个link

【问题讨论】:

    标签: node.js


    【解决方案1】:

    可能就像我现在的电脑一样,你的电脑也必须运行 McAfee 或其他程序已经在使用端口 8081,你有两个选择:

    • 停止 McAfee 或在该端口上运行的其他程序
    • 监听节点服务器上的不同端口

    【讨论】:

    • 如何监听不同的端口?
    • 你说 mccaffe 正在运行是对的,但我没有权限阻止它
    • 只需将8081更改为其他数字,通常对于nodejs端口是3000用于开发
    • 尝试发布 300,并在浏览器中 localhost:3000,告诉我会发生什么
    • 哇,当我使用 localhost:3000 时它会打印输出,所以为什么它不适用于 127.0.0.1:3000
    【解决方案2】:
    var http = require("http");
    
    http.createServer(function (request, response) {
    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.end('Hello World\n');
    }).listen(300);
    
    console.log('Server running at http://127.0.0.1:300/');
    

    我把它从 8081 改成 300 就可以了。

    http://127.0.0.1:300/ 这个 url 给出了想要的输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-22
      • 1970-01-01
      • 1970-01-01
      • 2010-12-13
      • 2019-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多