在某些 Linux 发行版上,尤其是 Ubuntu,非 root 用户无法绑定到小于 1024 的端口。 (有关证据,请参阅下面的笔记。)
有多种方法可以解决这个问题。见:
不过,更一般地说,要回答“如何让受 SSL 保护的网站在 Elastic Beanstalk 上运行”的问题。我想说:不要在你的应用程序中终止你的 TLS/SSL。
根据我的经验,使用弹性负载均衡器终止您的 SSL/TLS 是一个非常简单的解决方案。 (如果您使用 Amazon Certificate Manager (ACM) 颁发和管理您的证书)。 ACM 也会在到期前自动更新证书!
-
如果您确实希望将证书保留在实例上,那么我建议您使用“真正的”网络服务器,例如 nginx 来前端您的 nodejs 进程。 nginx 具有安装 SSL 证书 [1] 和插件的设施,可通过 LetsEncrypt [2] 自动发布和更新它们。很简单,这就是它的设计目的。
- 我不知道您使用的是哪个特定的 EB 平台,但其中许多(全部?)都预装了默认运行的 Web 服务器。 (例如,docker 平台运行
nginx,python 平台运行 apache)。因此,您的 EB 实例上可能已经安装了适当的 Web 服务器。
以下是在 Ubuntu docker 实例上执行的。 (该命令只是在指定端口启动python HTTP 服务器的一行命令。)您可以看到端口1025 始终有效。但是端口1023 只能作为root 使用。
root@24928b62f0bd:/# python3 -m http.server 1025
Serving HTTP on 0.0.0.0 port 1025 (http://0.0.0.0:1025/) ...
^C
Keyboard interrupt received, exiting.
root@24928b62f0bd:/# python3 -m http.server 1023
Serving HTTP on 0.0.0.0 port 444 (http://0.0.0.0:1023/) ...
^C
Keyboard interrupt received, exiting.
root@24928b62f0bd:/# useradd bob
root@24928b62f0bd:/# su bob
$ python3 -m http.server 1025
Serving HTTP on 0.0.0.0 port 1025 (http://0.0.0.0:1025/) ...
^C
Keyboard interrupt received, exiting.
$ python3 -m http.server 1023
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/lib/python3.6/http/server.py", line 1211, in <module>
test(HandlerClass=handler_class, port=args.port, bind=args.bind)
File "/usr/lib/python3.6/http/server.py", line 1185, in test
with ServerClass(server_address, HandlerClass) as httpd:
File "/usr/lib/python3.6/socketserver.py", line 456, in __init__
self.server_bind()
File "/usr/lib/python3.6/http/server.py", line 136, in server_bind
socketserver.TCPServer.server_bind(self)
File "/usr/lib/python3.6/socketserver.py", line 470, in server_bind
self.socket.bind(self.server_address)
PermissionError: [Errno 13] Permission denied
$
[1]http://nginx.org/en/docs/http/configuring_https_servers.html
[2]https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04