在 ubuntu apache2 上找不到 https url

在 ubuntu apache2 上找不到 https url

尝试在安装了 Apache 的 Ubuntu 服务器上配置 Apache2 上的 SSL

sudo apt install apache2
Opened ufw firewall
sudo ufw allow 'Apache'
ufw allow https

在 /root/cert 中安装 SSL 文件

  chmod 400 /root/cert/*
  chmod 500 /root/cert/

在 /etc/apache2/sites-available 中

Error:
Your browser sent a request that this server could not understand.
    Reason: You're speaking plain HTTP to an SSL-enabled server port.
    Instead use the HTTPS scheme to access this URL, please.
Apache/2.4.41 (Ubuntu) Server at 127.0.0.1 Port 443

https://www.domainnname.com

Error:
Not found
The requested URL was not found on this server.
Apache/2.4.41 (Ubuntu) Server at green-synapse.com Port 443

http://本地主机

shows domain wordpress website correctly

https://本地主机

Not Found
The requested URL was not found on this server.

default-ssl.conf 已配置

DocumentRoot /var/www/domainname/index.html
The index.html file exists

配置了 000-default.conf

ServerName domainname.com
DocumentRoot /var/www/domainname/index.html

配置的domainname.conf

 <VirtualHost *:80>
 ServerAdmin [email protected]
    Servername domainname.com
ServerAlias domainname.com
DocumentRoot /var/www/domainname/index.html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
    ServerAdmin [email protected]
    Servername domainname.com
    ServerAlias www.green-synapse.com
    DocumentRoot /var/www/domainname/index.html
# SSL
    SSLEngine on
SSLCertificateFile /root/cert/domain.crt
    SSLCertificateKeyFile /root/cert/domain.key
    SSLCertificateChainFile /root/cert/ca_bundle.crt

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

wordpress配置文件

<VirtualHost *:80>
 DocumentRoot /srv/www/wordpress
 <Directory /srv/www/wordpress>
   Options FollowSymLinks
   AllowOverride Limit Options FileInfo
   DirectoryIndex index.php
   Require all granted
 </Directory>
 <Directory /srv/www/wordpress/wp-content>
   Options FollowSymLinks
   Require all granted
 </Directory>
</VirtualHost>
<VirtualHost *:80>
 DocumentRoot /srv/www/wordpress
 <Directory /srv/www/wordpress>
   Options FollowSymLinks
   AllowOverride Limit Options FileInfo
   DirectoryIndex index.php
   Require all granted
 </Directory>
 <Directory /srv/www/wordpress/wp-content>
   Options FollowSymLinks
   Require all granted
 </Directory>
        SSLCertificateFile /root/cert/domainname.crt
        SSLCertificateKeyFile /root/cert/domainname.key
        SSLCertificateChainFile /root/cert/ca_bundle.crt
</VirtualHost>

sudo systemctl status apache2.service -l --no-pager

Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
 Active: active (running) since Tue 2023-11-14 12:47:10 CST; 9h ago
……
Starting The Apache HTTP Server...
Nov 14 12:47:10 gs2023 apachectl[30239]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
Started The Apache HTTP Server.
Reloading The Apache HTTP Server.
Warning: DocumentRoot [/var/www/green-synapse/index.html] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
Reloaded The Apache HTTP Server.
Reloading The Apache HTTP Server.
AH00112: Warning: DocumentRoot [/var/www/green-synapse/index.html] does not exist
 Reloaded The Apache HTTP Server.

我希望 https://domainname 显示 wordpress 网站,就像 http://localhost 正确显示 wordpress 网站一样

答案1

3 个 SSL 配置参数:

SSLCertificateFile /root/cert/domain.crt
SSLCertificateKeyFile /root/cert/domain.key
SSLCertificateChainFile /root/cert/ca_bundle.crt

也必须出现在你的<VirtualHost *:443>wordpress.conf 中。

由于ServerName www.domainname.com参数的原因,domainname.conf 中的 Virtualhost 仅当您通过以下方式访问您的网络服务器时才使用http://www.域名.com,如果您使用 http://localhost 则不会。

我认为这是您的 ERR_SSL_PROTOCOL_ERROR 的根本原因。

编辑:

我认为您应该删除(或移开以禁用它)您的 domainname.conf 文件。

然后,在 wordpress.conf 中:

  • Servername domainname.com在两行之后添加Virtualhost(不确定是否强制)
  • 将第二个虚拟主机的端口更改为 443
  • 在行SSLEngine on前添加SSLCertificateFile

然后尝试从你的服务器访问 https://localhost 或者https://域名.com从你的“服务器外的浏览器”

应该会更好。

答案2

我使用以下内容编辑了 etc/apache2/sites-available/default-ssl.conf 文件,重新启动,Apache 正在监听端口 443。

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
    ServerAdmin [email protected]
            DocumentRoot /srv/www/wordpress
            ServerName www.domain.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    SSLEngine on
    SSLCertificateFile /root/cert/domianname.com.crt
        SSLCertificateKeyFile /root/cert/domainname.com.key

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
            SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
            SSLOptions +StdEnvVars
    </Directory>
</VirtualHost>
</IfModule>

相关内容