无法连接到服务器端口 443:连接被拒绝

无法连接到服务器端口 443:连接被拒绝

我的服务器上运行着一个 Web 服务器,地址是 127.0.0.1:8088,我想从互联网上访问它。

运行 Web 服务器时的 ss -nplut 输出:

tcp LISTEN 0 1024 127.0.0.1:8088 0.0.0.0:* users:(("ctprods",pid=2042,fd=9))

输出 ss -nplut |grep 443

tcp LISTEN 0 511 *:443 *:*

我创建了一个 apache 虚拟主机(站点已启用,apache 已重新加载):

<VirtualHost *:443>
 # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName cyprientaque.com
    ServerAlias ctprods.cyprientaque.com

    ServerAdmin [email protected]

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.

#       RewriteCond %{SERVER_NAME} =ctprods.cyprientaque.com
#       RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

     <Proxy *>
             Require all granted
     </Proxy>
             ProxyPass / http://127.0.0.1:8088/
             ProxyPassReverse / http://127.0.0.1:8088/

SSLCertificateFile /etc/letsencrypt/live/ctprods.cyprientaque.com-0001/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/ctprods.cyprientaque.com-0001/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

我使用 lets encrypt 创建了一个 SSL 证书:

Certificate Name: ctprods.cyprientaque.com-0001
Serial Number: 39538aec7472a644e8d22887f858de17177
Domains: ctprods.cyprientaque.com
Expiry Date: 2020-11-17 10:59:58+00:00 (VALID: 89 days)
Certificate Path: /etc/letsencrypt/live/ctprods.cyprientaque.com-0001/fullchain.pem
Private Key Path: /etc/letsencrypt/live/ctprods.cyprientaque.com-0001/privkey.pem

我的 DNS 提供商中有一个 ctprods.cyprientaque.com 的 A 记录,指向我的服务器 IP

但是当我尝试使用 curl 访问我的服务器时,出现错误:

$ curl -X GET https://ctprods.cyprientaque.com/projects
curl: (7) Failed to connect to ctprods.cyprientaque.com port 443: Connection refused 

而且我看不到请求 tcpdump 端口 443。

答案1

您的 Apache 未监听端口 443。您仅为 HTTP 配置了 VirtualHost,而不是为 HTTPS 配置。使用端口 443 和您的证书配置第二个 VirtualHost,并确保您Listen 443的 Apache 配置中有指令。您的证书不属于:80VirtualHost。

以上内容基于问题中的错误信息。无论您在此期间做了什么,您的服务器现在都可以通过 HTTPS 访问。

$ curl -X GET https://ctprods.cyprientaque.com/projects
"Invalid JWT"

相关内容