Настройка SSL с виртуальными хостами под Apache и CentOS

У меня два веб-сайты, обслуживаемые экземпляром CentOS. У одного из них включен SSL, другой обслуживается только через порт 80.

Итак, http://siteone.com и https://siteone.com работают хорошо, как и http://sitetwo.com .

Проблема в том, что https: // sitetwo. com отображает https://siteone.com .

У меня есть один общедоступный IP-адрес.

Я думаю, что это тот случай, когда я не могу обслуживать два https-сайта с одного IP-адреса. , но есть ли хотя бы способ перенаправить 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
8
задан 23 December 2015 в 03:25
2 ответа

Два https могут подаваться на одном IP. Вам просто нужно убедиться, что конфигурация виртуального хоста работает.

Вы уверены, что ваш виртуальный хост работает? Вы можете использовать эту конфигурацию на сайте.

<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>

Может быть, вы можете обратиться к this для ssl-учебника.

И, наконец, вы можете получить доступ к вашему веб сайту, как этот
https://example. com
https://example2.com

15
ответ дан 2 December 2019 в 22:50

Вы также можете попробовать это

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public
    <Directory /var/www/example.com>
    Options +FollowSymlinks
    AllowOverride All
    Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
0
ответ дан 1 November 2020 в 10:51

Теги

Похожие вопросы