简体   繁体   中英

ERR_CONNECTION_REFUSED over HTTP but HTTPS works fine

I dont see why i get ERR_CONNECTION_REFUSED over http but https works just fine. My virtual hosts file:

<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>

What am i doing wrong? Also i want to redirect http to https. But its not doing anything at the moment.

Thanks!

To redirect use this on .htacess instead of 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>

And for first 2 lines if that doesn't work use this in replace of first 2 lines:

RewriteCond %{ENV:HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

That redirects www to root as well to not then delete RewriteCond %{HTTPS} on [OR] RewriteCond %{HTTP_HOST} ^www. [NC] RewriteRule ^ https://antimalwareprogram.co% {REQUEST_URI} [R=301,L,NE] RewriteCond %{HTTPS} on [OR] RewriteCond %{HTTP_HOST} ^www. [NC] RewriteRule ^ https://antimalwareprogram.co% {REQUEST_URI} [R=301,L,NE]

Note: Replace antimalwareprogram.co with your site URL Keep % as that redirects to there current URL or it'll redirect to your home page and this redirect fixes http error as http won't exist!

HOPE THIS HELPED!

监听80从配置中丢失

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM