如何正确设置 Apache VirtualHost 为 HTTP 和 HTTPS?

如何正确设置 Apache VirtualHost 为 HTTP 和 HTTPS?

我正在尝试使用 Apache 和 mod_ssl 设置本地(用于开发/测试目的)SSL 站点,这是我的 VirtualHost 文件中的内容:

/etc/httpd/conf.d/local.conf
<VirtualHost *:80>
    ServerName reptool.dev

    DocumentRoot /var/www/html/magnific/reptooln_admin/web
    <Directory /var/www/html/magnific/reptooln_admin/web>
        # enable the .htaccess rewrites
        AllowOverride All
        Order allow,deny
        Allow from All
    </Directory>

    ErrorLog /var/log/httpd/reptool-error.log
    CustomLog /var/log/httpd/reptool-access.log combined
</VirtualHost>

/etc/httpd/conf.d/local-ssl.conf
<VirtualHost reptool.dev:443>
    ServerName reptool.dev:443

    DocumentRoot /var/www/html/magnific/reptooln_admin/web
    <Directory /var/www/html/magnific/reptooln_admin/web>
        # enable the .htaccess rewrites
        AllowOverride All
        Order allow,deny
        Allow from All
    </Directory>

    ErrorLog /var/log/httpd/reptool-error.log
    CustomLog /var/log/httpd/reptool-access.log combined

    SSLEngine on
    SSLCertificateFile /etc/pki/tls/certs/ca.crt
    SSLCertificateKeyFile /etc/pki/tls/private/ca.key
</VirtualHost>

第一个(非 SSL)工作正常,但使用 SSL 时我没有收到错误 404:

The requested URL /app_dev.php was not found on this server.

为什么?我在配置层面缺少什么?

答案1

您的服务器名称“reptool.dev:443”在我看来不正确,它不应该包含端口。请尝试:

ServerName reptool.dev

相关内容