Ubuntu

Apache 將 https:b-site 訪問者定向到 https:a-site(b-site 沒有 ssl)

  • December 18, 2021

我的 apache 系統有問題。它是全新的,我也是。

我現在的問題是,如果有人訪問https://123.446.689.0>或<https://b-site.com(沒有任何 ssl),那麼 a-site 會在 https…

一個連接怎麼會這樣跳躍?(當然會出現警告,因為 ssl 是針對另一個域的)

我將在 b 站點上獲得 ssl,但無法獲得 ssl 到 ip。並且所有直接 IP 訪問都應重定向到另一個站點。(目前是 000-預設值)

這些是我的配置文件;

a-site.com.conf

&lt;VirtualHost a-site.com:80&gt;
ServerName a-site.com
DocumentRoot /var/www/a-site.com
   &lt;Directory /var/www/a-site.com&gt;
       Options FollowSymLinks
       AllowOverride Limit Options FileInfo
       DirectoryIndex index.html index.php
       Require all granted

   &lt;/Directory&gt;
&lt;Directory /var/www/a-site.com/wp-content&gt;
       Options FollowSymLinks
       Require all granted

   &lt;/Directory&gt;

ErrorLog ${APACHE_LOG_DIR}/a-site.error.log
CustomLog ${APACHE_LOG_DIR}/a-site.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =a-site.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
&lt;/VirtualHost&gt;

a-conf.com-le-ssl.conf

&lt;IfModule mod_ssl.c&gt;
&lt;VirtualHost a-site.com:443&gt;
   ServerName a-site.com
   ServerAdmin arga@localhost
   DocumentRoot /var/www/a-site.com
   ErrorLog ${APACHE_LOG_DIR}/a-site.error.log
   CustomLog ${APACHE_LOG_DIR}/a-site.access.log combined


SSLCertificateFile /etc/letsencrypt/live/a-site.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/a-site.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
Header always set Strict-Transport-Security "max-age=31536000"
&lt;/VirtualHost&gt;
&lt;/IfModule&gt;

000-default.conf

&lt;VirtualHost 123.456.789.0:80&gt;
       ServerAdmin webmaster@localhost
       DocumentRoot /var/www/00
       ErrorLog ${APACHE_LOG_DIR}/catchall.error.log
       CustomLog ${APACHE_LOG_DIR}/catchall.access.log combined

&lt;/VirtualHost&gt;

b-site.com.conf

&lt;VirtualHost b-site.com:80&gt;
ServerName b-site.com
DocumentRoot /var/www/b-site.com
   &lt;Directory /var/www/b-site.com&gt;
       Options FollowSymLinks
       AllowOverride Limit Options FileInfo
       DirectoryIndex index.html index.php
       Require all granted

   &lt;/Directory&gt;
&lt;Directory /var/www/b-site.com/wp-content&gt;
       Options FollowSymLinks
       Require all granted

   &lt;/Directory&gt;

ErrorLog ${APACHE_LOG_DIR}/b-site.error.log
CustomLog ${APACHE_LOG_DIR}/b-site.log combined

&lt;/VirtualHost&gt;

000-預設-ssl.conf

&lt;IfModule mod_ssl.c&gt;
 
&lt;VirtualHost _default_:443&gt;
           ServerAdmin webmaster@localhost
           DocumentRoot /var/www/00
           
           ErrorLog ${APACHE_LOG_DIR}/napto.def.error.log
           CustomLog ${APACHE_LOG_DIR}/napto.def.access.log combined
           SSLEngine on

           SSLCertificateFile      /etc/ssl/certs/ssl-cert-snakeoil.pem
           SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
           &lt;FilesMatch "\.(cgi|shtml|phtml|php)$"&gt;
                           SSLOptions +StdEnvVars
           &lt;/FilesMatch&gt;
           &lt;Directory /usr/lib/cgi-bin&gt;
                           SSLOptions +StdEnvVars
           &lt;/Directory&gt;             
       &lt;/VirtualHost&gt;
&lt;/IfModule&gt;

您只a-site.com:443 VirtualHost定義了埠 443 (https),​​因此 Apache 只顯示它可以找到顯示的站點。

您需要以與您相同的方式VirtualHost在埠 443 上定義預設值(或檢查您是否擁有並啟用它)。您仍然需要預設主機的 TLS/SSL 證書,但您可以創建自簽名證書。基於 Debian 的系統已經為您生成了一個.&lt;VirtualHost _default_:443&gt;``000-default.conf``default-ssl.conf``/etc/ssl/certs/ssl-cert-snakeoil.pem

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