https 站点的 httpd.conf 配置?

https 站点的 httpd.conf 配置?

我在 httpd.conf 中配置了一个这样的子站点

<VirtualHost *:80>
ServerName myadmin.mysite.com
DocumentRoot /var/www/html/myadmin
DirectoryIndex index.php
<Directory /var/www/html/myadmin>
    AllowOverride All
    Allow from All
</Directory>
</VirtualHost>

但我希望 phpmyadmin 强制使用 https 连接。如果我这样做,则在其配置文件 config.inc.php 中通过以下内容:

$cfg['ForceSSL'] = true;

我被重定向到“Apache 2 测试页面”(在 https 上)。我需要进行哪些更改才能使 phpmyadmin 连接仅通过 https 进行

答案1

您必须创建虚拟主机的副本,将其端口设置为 443 并添加 SSL 配置指令。

<VirtualHost *:443>
  ServerName myadmin.mysite.com

  SSLEngine on
  SSLProtocol all -SSLv2
  SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
  SSLCertificateFile conf/ssl-keys/server.crt
  SSLCertificateKeyFile conf/ssl-keys/server.key


  DocumentRoot /var/www/html/myadmin
  DirectoryIndex index.php
  <Directory /var/www/html/myadmin>
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

答案2

定义 ssl vhost

<ifmodule mod_ssl.c>

<virtualhost *:443>
servername myadmin.mysite.com
documentroot /var/www/html/myadmin
directoryindex index.php
#your rest of configs + ssl cert,key,etc
sslengine on
</virtualhost>
</ifmodule>

答案3

以下是从 http 重定向到 https 的一些示例:

<VirtualHost *:443>
        ServerName myadmin.mysite.com

        SSLEngine On
        SSLCertificateFile {path-to-certificate}
        SSLCertificateKeyFile {path-to-key}
        DocumentRoot /var/www/html/myadmin
        DirectoryIndex index.php
        <Directory /var/www/html/myadmin>
            AllowOverride All
            Allow from All
        </Directory>
</VirtualHost>

<VirtualHost *:80>
        ServerName myadmin.mysite.com
        DocumentRoot /var/www/html/myadmin

        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

相关内容