node.js - 具有 nginx 和基本身份验证的 Node.js 服务器

标签 node.js nginx server basic-authentication

我正在尝试使用基本身份验证在 nginx 后面运行一个 node.js 服务器。这是我的最小配置:

server {
  auth_basic "closed website";
  auth_basic_user_file /etc/nginx/.htpasswd;

  location / {
    proxy_pass  http://localhost:3000/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

我的第一个问题是,当我转到 x.x.x.x 时,每次(无限期地)我按下回车键(无论我设置为登录名和密码 - 即使是好的)时,基本身份验证表单都会重新出现。

服务器只是返回一些纯文本 res.end("Hello World\n");,在基本身份验证表单再次出现之前我可以看到它一秒钟。

第二个问题,是否可以阻止 x.x.x.x:3000(如果不能,则在 :80 上设置身份验证没有意义)。

谢谢!

顺便说一句,这是我第一次设置 nginx(我已经花了很多时间在上面)。

注意:它在没有基本身份验证的情况下工作(或者在我的位置关闭 auth_basic;)。

目前我的网站看起来总是这样: enter image description here :)

最佳答案

好的我的错,知道了!

显然是 .htpasswd have to be encrypted 中的密码, openssl passwd 工作得很好。

第二个问题很简单,iptables 就是为了解决这个问题。

希望这对其他 nginx 新用户有帮助!

关于node.js - 具有 nginx 和基本身份验证的 Node.js 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32917168/

相关文章:

php - 是否可以在同一个 Dockerfile 中包含 PHP + MongoDb + Nginx?

c++ - 使用nginx在c++中使用fastcgi访问环境变量

linux - 无法删除超过三天的目录

python - 停止 Mesa 服务器

javascript - 如何将 sails.js 模型与关联一起使用?

javascript - Streaming-s3 没有正确上传文件到 aws

android客户端将多部分表单数据解析为非ascii

node.js - NodeJs fs.watch/FSWatcher 错误

nginx - 使用 ffmpeg 转码扩展 nginx-rtmp 直播

html - 我如何使用 vscode 中的实时服务器在移动设备上查看我的 html 文件?