我不知道为什么我通过http获得ERR_CONNECTION_REFUSED,但https工作得很好。我的虚拟主机文件:
<VirtualHost *:80>
ServerName yourdomain.com
Redirect permanent / https://www.yourdomain.com/
</VirtualHost>
<IfModule mod_ssl.c>
Listen 443 https
<VirtualHost *:443>
DocumentRoot /var/www/yourdomain.com/public
ServerName localhost
ErrorLog /var/www/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# SSL Configuration
SSLEngine on
SSLProtocol ALL -SSLv2 -SSLv3
SSLHonorCipherOrder On
SSLCompression Off
SSLCertificateFile /etc/apache2/ssl/yourdomain.crt
SSLCertificateKeyFile /etc/apache2/ssl/yourdomain.key
SSLCACertificateFile /etc/apache2/ssl/yourdomain.ca-bundle
ServerSignature Off
<Directory /var/www/yourdomain.com/public>
Options Indexes FollowSymlinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
我做错了什么?我还想将http重定向到https。但它目前没有做任何事情。
谢谢!
答案 0 :(得分:0)
要重定向,请使用.htacess而不是virtualhost
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://antimalwareprogram.co% {REQUEST_URI} [R=301,L,NE]
</IfModule>
对于前两行如果不起作用,请使用此代替前两行:
RewriteCond %{ENV:HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
将www重定向到root也不会删除 RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteRule ^ https://antimalwareprogram.co% {REQUEST_URI} [R=301,L,NE]
注意:将antimalwareprogram.co替换为您的站点URL 保留%,因为它重定向到当前URL或它将重定向到您的主页,此重定向修复http错误,因为http将不存在!
答案 1 :(得分:0)
配置
中缺少Listen 80