如何使用密码保护 Node 服务器?

发布于 2024-12-23 05:55:22 字数 399 浏览 4 评论 0 原文

我对 Node 和 Javascript 都很陌生,当谈到 PHP 和 Apache/nginx 时我完全迷失了。我有一个运行节点服务器的 Amazon EC2 实例,我通过浏览器通过 http://[my-ip]:[port-number]/ 访问该实例。

我想完成几件事——最重要的是,我想在服务器接受客户端之前需要用户名/密码。第二个目标是通过某种代理转发取消端口号规范,但我认为为了密码保护服务器可能需要这个目标。

我看到其他人通过调整服务器配置和/或其他实用程序(例如 haproxy)来完成此任务,但这些示例有点超出我的理解范围,我想了解我在每个步骤中所做的事情,因为对我来说这个项目更多的是关于学习而不是其他任何事情。

再说一遍,我非常缺乏经验,所以如果我能就如何去做这件事提供一个易于遵循、自下而上的建议,我将非常感激!

I am very new to both node and Javascript, and am completely lost when it comes to PHP and Apache/nginx. I have an Amazon EC2 instance running my node server, which I am accessing through my browser via http://[my-ip]:[port-number]/.

There are a couple of things I'd like to accomplish -- most importantly, I'd like to require a username/password before the server will accept a client. A secondary objective, but one that I feel may be required in order to password protect the server, is to do away with the port number specification through some kind of proxy forwarding.

I've seen that others have accomplished this by adjusting server configurations and/or other utilities such as haproxy, but the examples were a little over my head and I'd like to understand what I'm doing at each step, because for me this project is more about learning than anything else.

Again, I am VERY inexperienced, so an easy-to-follow, bottom-up suggestion for how I should go about doing this would be very much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

意中人 2024-12-30 05:55:22

因此,让我们将您的问题分为两个:

a)密码保护服务器

我猜您正在谈论基本的 HTTP 身份验证。如果您使用 Express,则可以使用 Connect 中间件来实现此目的。

在这里找到示例: https://github.com/senchalabs/连接/blob/master/lib/middleware/basicAuth.js
在这里阅读更多相关信息: http://senchalabs.github.com/connect/middleware-basicAuth .html

b) 您需要一个代理。在生产中,我建议像您建议的那样选择 HAProxy ,但还有其他用 Node.js 编写的替代方案。 bouncynode-http-proxy 你可以发现它更容易理解。

So let's split your question into two:

a) Password protect server

I'm guessing you are talking about the basic HTTP auth. If you are using Express, you can use the Connect middleware in order to achieve that.

Find the example here: https://github.com/senchalabs/connect/blob/master/lib/middleware/basicAuth.js
Read more about it here: http://senchalabs.github.com/connect/middleware-basicAuth.html

b) You want a proxy. In production I'd say to choose HAProxy like you were suggested, but there are also other alternatives written in Node.js like bouncy or node-http-proxy which you can find more easy to understand.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文