Ubuntu 错误连接被HTTP拒绝,但HTTPS工作正常

Ubuntu 错误连接被HTTP拒绝,但HTTPS工作正常,ubuntu,Ubuntu,我不明白为什么我在http上得到错误的连接,但是https工作得很好。我的虚拟主机文件: <VirtualHost *:80> ServerName yourdomain.com Redirect permanent / https://www.yourdomain.com/ </VirtualHost> <IfModule mod_ssl.c> Listen 443 https <VirtualHost *:443> DocumentRoo

我不明白为什么我在http上得到错误的连接,但是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>

ServerName yourdomain.com
重定向永久/https://www.yourdomain.com/
听443https
DocumentRoot/var/www/yourdomain.com/public
服务器名本地主机
ErrorLog/var/www/error.log
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
#SSL配置
斯伦金安
SSLProtocol ALL-SSLv2-SSLv3
SSLHonorCipherOrder开启
SSL压缩关闭
SSLCertificateFile/etc/apache2/ssl/yourdomain.crt
SSLCertificateKeyFile/etc/apache2/ssl/yourdomain.key
SSLCACertificateFile/etc/apache2/ssl/yourdomain.ca-bundle
服务器签名关闭
选项索引跟随符号链接
允许超越所有
要求所有授权
我做错了什么?我还想将http重定向到https。但目前它什么也没做


谢谢

若要重定向,请在.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>
将www重定向到根目录,然后在[OR]上删除
RewriteCond%{HTTPS}
重写cond%{HTTP_HOST}^www.[NC]
重写规则^{REQUEST_URI}[R=301,L,NE]

注意:用您的网站URL替换antimalwareprogram.co 将%保留为重定向到当前URL,否则它将重定向到您的主页,此重定向将修复http错误,因为http将不存在


希望这有帮助 Listen 80在配置中丢失了

我假设在实际文件中,*:80的服务器名设置与*:443的服务器名完全相同?(只是问一下*:443你把它显示为本地主机,但是*:80你把它删除到yourdomain.com上了)@EdmCoff是的,就是这样你看到我的答案了吗?那对你有帮助吗?
RewriteCond %{ENV:HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]