Https

在 Apache 和 CentOS 下使用虛擬主機配置 SSL

  • April 17, 2022

我有兩個從 CentOS 實例提供服務的網站。其中一個啟用了 SSL,另一個僅在埠 80 上提供服務。

因此,http://siteone.com兩者https://siteone.com都可以正常工作,http://sitetwo.com.

問題是https://sitetwo.com顯示https://siteone.com.

我有一個可用的公共 IP 地址。

我認為這是我無法從一個 IP 提供兩個 https 站點的情況,但至少有一種方法可以將 https 重定向到埠 80,https://sitetwo.com而不是提供錯誤的站點?

sudo apachectl -S
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using xxx.xxx.xxx.xxx. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:

▽
xxx.xxx.xxx.xxx:443     siteone.com (/etc/httpd/sites-enabled/ssl-siteone.conf:1)
*:80                   is a NameVirtualHost
        default server beta-siteone (/etc/httpd/sites-enabled/beta-siteone.conf:1)
        port 80 namevhost beta-ilegis (/etc/httpd/sites-enabled/beta-siteone.conf:1)
                alias beta.siteone.com
        port 80 namevhost siteone.com (/etc/httpd/sites-enabled/siteone.conf:1)
                alias www.siteone.com
        port 80 namevhost sitetwo.com (/etc/httpd/sites-enabled/sitetwo.com.conf:1)
                alias www.sitetwo.com
*:443                  is a NameVirtualHost
        default server xxx.xxx.xxx.xxx (/etc/httpd/conf.d/ssl.conf:56)
        port 443 namevhost xxx.xxx.xxx.xxx (/etc/httpd/conf.d/ssl.conf:56)
        port 443 namevhost xxx.xxx.xxx.xxx (/etc/httpd/sites-enabled/ssl-sitetwo.com.conf:1)
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/run/httpd/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
Mutex ssl-stapling: using_defaults
PidFile: "/run/httpd/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48
Group: name="apache" id=48

一個 IP 可以提供兩個 https。您只需要驗證虛擬主機配置是否有效。

你確定你的虛擬主機可以工作嗎?您可以在站點可用中使用此配置。

<VirtualHost *:80>
   ServerName www.example.com
   ServerAlias example.com
   DocumentRoot /var/www/example.com/public_html
   ErrorLog /var/www/example.com/error.log
   CustomLog /var/www/example.com/requests.log combined
</VirtualHost>

<VirtualHost *:80>
   ServerName www.example2.com
   DocumentRoot /var/www/example2.com/public_html
   ServerAlias example2.com
   ErrorLog /var/www/example2.com/error.log
   CustomLog /var/www/example2.com/requests.log combined
</VirtualHost>

按照這裡的教程

如果您確定您的虛擬主機配置,那麼您可以像這樣更改配置:

<VirtualHost *:443>
   ServerName www.example.com
   ServerAlias example.com
   DocumentRoot /var/www/example.com/public_html
   ErrorLog /var/www/example.com/error.log
   CustomLog /var/www/example.com/requests.log combined
   SSLEngine on
   SSLCertificateFile /etc/apache2/ssl/example/apache.crt
   SSLCertificateKeyFile /etc/apache2/ssl/example/apache.key
</VirtualHost>

<VirtualHost *:443>
   ServerName www.example2.com
   DocumentRoot /var/www/example2.com/public_html
   ServerAlias example2.com
   ErrorLog /var/www/example2.com/error.log
   CustomLog /var/www/example2.com/requests.log combined
   SSLEngine on
   SSLCertificateFile /etc/apache2/ssl/example2/apache.crt
   SSLCertificateKeyFile /etc/apache2/ssl/example2/apache.key
</VirtualHost>

也許你可以參考這個ssl 教程。

最後,您可以像這樣訪問您的網站

https://example.com

https://example2.com

引用自:https://serverfault.com/questions/744960