我有一个网站,我已经为其设置了VHost。我需要HTTP和HTTPS。虽然HTTP似乎运行良好,但每当我访问HTTPS功能时,我都会收到“Safari无法打开服务器”消息。我怀疑问题出在http_vhosts.conf文件中。以下是相关网站的条目。可能出现什么问题?
<Virtualhost *:80>
VirtualDocumentRoot "/Users/xxx/www/sites/xxxxxx"
ServerName http://xxxxxx.dev
ServerAlias xxxxxx.dev
UseCanonicalName on
<Directory "/Users/xxx/www/sites/xxxxxx">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</Virtualhost>
<Virtualhost *:443>
VirtualDocumentRoot "/Users/xxx/www/sites/xxxxxx"
ServerName https://xxxxxx.dev
ServerAlias https://xxxxxx.dev
UseCanonicalName off
<Directory "/Users/xxx/www/sites/xxxxxx">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</Virtualhost>
答案 0 :(得分:0)
您需要添加证书:
<Virtualhost *:443>
VirtualDocumentRoot "/Users/xxx/www/sites/xxxxxx"
ServerName https://xxxxxx.dev
ServerAlias https://xxxxxx.dev
UseCanonicalName off
<Directory "/Users/xxx/www/sites/xxxxxx">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
</Virtualhost>
要创建自签名证书,您可以使用以下命令:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
顺便说一下,如果您的SeverAlias与您的ServerName相同,您可以删除ServerAlias,它不是必需的