Если нужно альтернативные имена, в /etc/ssl/openssl.cnf поправить раздел v3_req и добавить @alt_names. В этом же файле можно указать остальные параметры, чтобы не вводить во время команды.
|
1 2 3 4 5 6 7 8 9 10 |
[ v3_req ] # Extensions to add to a certificate request basicConstraints = CA:FALSE keyUsage = nonRepudiation, digitalSignature, keyEncipherment subjectAltName = @alt_names [ alt_names ] DNS.1 = hostname.domain.loc DNS.2 = hostname IP.1 = 192.168.1.140 |
Создать ключ с сертификатом командой:
|
1 |
sudo openssl req -x509 -nodes -days 36500 -newkey rsa:2048 -keyout /etc/ssl/private/hostname.domain.loc.key -out /etc/ssl/certs/hostname.domain.loc.crt -extensions v3_req -config /etc/ssl/openssl.cnf |
Создать ключи Диффи-Хеллмана
|
1 |
openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048 |
Создать файл /etc/apache2/conf-available/ssl-params.conf
|
1 2 3 4 5 6 7 8 9 10 11 12 |
SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH SSLProtocol All -SSLv2 -SSLv3 SSLHonorCipherOrder On Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload" Header always set X-Frame-Options DENY Header always set X-Content-Type-Options nosniff # Requires Apache >= 2.4 SSLCompression off SSLSessionTickets Off SSLUseStapling on SSLStaplingCache "shmcb:logs/stapling-cache(150000)" SSLOpenSSLConfCmd DHParameters "/etc/ssl/certs/dhparam.pem" |
Настройка виртуального хоста для https в файле /etc/apache2/sites-available/default-ssl.conf
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<VirtualHost *:443> ServerAdmin webmaster@localhost ServerName hostname.domain.loc ServerAlias *.hostname.domain.loc DocumentRoot /opt/observium/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLEngine on SSLCertificateFile /etc/ssl/certs/hostname.domain.loc.crt SSLCertificateKeyFile /etc/ssl/private/hostname.domain.loc.key <FilesMatch "\.(?:cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory /usr/lib/cgi-bin> SSLOptions +StdEnvVars </Directory> <Directory /opt/observium/html/> DirectoryIndex index.php Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> BrowserMatch "MSIE [2-6]" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 </VirtualHost> |
Если нужна переадресация с http, то в http хосте добавить Redirect:
|
1 2 3 4 5 |
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName hostname.domain.loc Redirect "/" "https://hostname.domain.loc" DocumentRoot /opt/observium/html |
Включить модуль Apache для SSL, mod_ssl, модуль mod_headers, для работы сниппета SSL и https хост:
|
1 2 3 |
sudo a2enmod ssl sudo a2enmod headers sudo a2ensite default-ssl |
Проверка настроек командой sudo apache2ctl configtest, может выдать ошибку, что Syntax OK, но директива ServerName не установлена глобально в /etc/apache2/apache2.conf. Это делать не обязательно.
Перезагрузить Apache командой sudo systemctl restart apache2.