【问题标题】:Apache cannot bind :443 address for SSL even though port 443 is unused即使端口 443 未使用,Apache 也无法为 SSL 绑定 :443 地址
【发布时间】:2017-05-17 22:38:54
【问题描述】:

我最近使用 openssl 1.0.2j 安装了启用 SSL 的 Apache 2.4.20。

更新 httpd.conf 和 httpd-ssl.conf 文件并尝试在侦听端口 443 时启动 Apache,我收到以下错误:

(13)Permission denied: -----: make_sock: could not bind to address [::]:443
(13)Permission denied: -----: make_sock: could not bind to address 0.0.0.0:443
no listening sockets available, shutting down

这是我的配置:

httpd.conf:

Listen 51000
#Listen 443
#Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf

httpd-ssl.conf

Listen 443

如果我在 httpd-ssl.conf 文件中注释掉这一行,我的 apache 就可以正常启动:

attempting to start apache
done

但是,我每次都会收到套接字错误。

我以 root 身份运行以下命令:

netstat -tlpn | grep :443

什么都没返回。

lsof -i tcp:443

什么都没返回。

我在某处读到只有 root 可以绑定到低于 1024 的地址,但我不知道该声明的有效性。 Apache 没有以 root 身份运行 - 这会是问题吗?

【问题讨论】:

  • 我也有同样的问题。如果您实际上无法指定要侦听的 HTTPS 端口和 IP 地址,甚至在 ssl.conf 中有一个 Listen 选项似乎有点愚蠢。奇怪的是,在我的情况下,如果我注释掉 Listen 选项,那么 Apache 无论如何都会默认侦听 *:443,而不是特定的 IP 地址。

标签: linux apache ssl ports


【解决方案1】:

问题是 443 是一个特权端口,而您正试图以非 root 用户身份进行侦听。

请参阅:privileged portswhy are privileged ports restricted to root

There are also ways to get non-root users to bind to privileged ports

【讨论】:

  • 感谢您的回答 - 我今天早些时候读到那篇文章时担心是这样。我将研究解决方法,看看是否适用于我的情况。
【解决方案2】:

如果你使用 docker 和 docker-compose,

当我们使用像 bitnami 官方图像这样的非根容器时会发生这种情况。

当需要与主机网络绑定时,我们使用了user:rootnetwork_mode:host

  apache:
    image: bitnami/apache:2.4
    container_name: "apache"
    ports:
      - 80:80
    network_mode: host
    privileged: true
    user: root
    environment:
      DOCKER_HOST: "unix:///var/run/docker.sock"
    env_file:
      - .env
    volumes:
      - ./setup/apache/httpd.conf:/opt/bitnami/apache/conf/httpd.conf

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 2015-05-12
    • 2010-10-29
    • 2018-03-20
    • 2017-08-28
    • 1970-01-01
    • 2014-07-10
    • 2014-03-01
    • 2017-10-07
    • 2019-03-06
    相关资源
    最近更新 更多