Я использую Apache, и у меня есть два домена, к которым я создал виртуальные хосты и установил сертификаты SSL. Однако только один домен работает и другие просто перенаправления к этому домену. Я думаю, что это вызвано тем, что сайт, каждый - основной сайт и мне нужен отдельный IP-адрес для каждого домена при использовании SSL?
Я прочитал довольно много статей, в которых говорится, что можно использовать несколько сертификатов SSL с одним IP путем выполнения следующего в виртуальном хосте
<VirtualHost *:443>
Я попробовал это, но это не работает на меня. Также много статей упоминает SNI, но я не на 100% уверен, что это означает. Кто-то мог пролить некоторый свет на это и указать на меня в правильном направлении?
Это - то, на что похожи мои виртуальные хосты
Сайт 1
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin email@gmail.com
ServerName domain.com
ServerAlias www.domain.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /var/www/html/domain.com/public_html
Redirect permanent / https://www.domain.com
<Directory "/var/www/html/domain.com/public_html">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
# Log file locations
LogLevel warn
#ErrorLog /var/www/html/domain.com/log/error.log
#CustomLog /var/www/html/domain.com/log/access.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin email@gmail.com
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/html/domain.com/public_html
<Directory "/var/www/html/domain.com/public_html">
#Options Indexes FollowSymLinks MultiViews
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /etc/apache2/ssl/www_domain_com/www_domain_com.crt
SSLCertificateKeyFile /etc/apache2/ssl/www_domain_com/server.key
# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
SSLCertificateChainFile /etc/apache2/ssl/www_domain_com/www_domain_com.ca-bundle
#...
</VirtualHost>
</IfModule>
Сайт 2
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin email@gmail.com
ServerName domain2.com
ServerAlias www.domain2.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.php index.html
DocumentRoot /var/www/html/domain2.com/public_html/public
# Redirect permanent / https://www.domain2.com
# Log file locations
LogLevel warn
ErrorLog /var/www/html/domain2.com/log/error.log
CustomLog /var/www/html/domain2.com/log/access.log combined
SetEnv CI_ENV production
SetEnv CI_BASE_URL http://www.domain2.com/
<Directory "/var/www/html/domain2.com/public_html/public">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /var/www/html/domain2.com/public_html/public/.htpasswd
Require valid-user
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin email@gmail.com
ServerName domain2.com
ServerAlias www.domain2.com
DocumentRoot /var/www/html/domain2.com/public_html/public
<Directory "/var/www/html/domain2.com/public_html/public">
#Options Indexes FollowSymLinks MultiViews
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /etc/apache2/ssl/www_domain2_com/www_domain2_com.crt
SSLCertificateKeyFile /etc/apache2/ssl/www_domain2_com/server.key
# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
SSLCertificateChainFile /etc/apache2/ssl/www_domain2_com/www_domain2_com.ca-bundle
#...
</VirtualHost>
</IfModule>
Вам не нужен IP на ssl домен, но Вам действительно нужна директива ServerName в каждом virtualhost. Следующее должно работать с помощью apache2. Это будет немного отличаться, если Вы не будете использовать apache2.
<час><VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName example.com
DocumentRoot /var/www
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName example.com
DocumentRoot /var/www
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /etc/apache2/ssl/example.com/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/example.com/apache.key
</VirtualHost>
</IfModule>
Решенный!
Конфигурация, применяющаяся только к одному из нескольких сайтов, принадлежит в конфигурацию сайта.
перемещение
<Directory /var/www/html/example.com>
AllowOverride All
</Directory>
ServerName example.com
от
/etc/apache2/apache2.conf
в
/etc/apache2/sites-available/example.conf