Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in AWS by (19.1k points)

My config is:

Listen 443 http

NameVirtualHost *:80

NameVirtualHost *:443

ServerName *:80

<VirtualHost *:80> 

  [some non-ssl stuff]

  ServerName account.example.com

</VirtualHost>

<VirtualHost *:443> 

  [some non-ssl stuff(directory, docroot)] 

  ServerName account.example.com

  SSLEngine on

  SSLCertificateFile /Users/myusername/certs/server.crt

  SSLCertificateKeyFile /Users/myusername/certs/server.key

</VirtualHost>

So I can't access the http version of my site, but ssl version is working correctly. I want to use both vhosts, http(80) and https(443) to rewrite http to https URL via mod_rewrite.

uname -a

Linux 3.4.62-53.42.amzn1.x86_64 GNU/Linux

httpd -v

Server version: Apache/2.2.25 (Unix)

Please help to understand what I'm doing wrong.

1 Answer

0 votes
by (44.4k points)

The config should be something like this:

Listen 443 http

Listen 80

NameVirtualHost *:80

NameVirtualHost *:443

ServerName *:80

<VirtualHost *:443> 

  [some non-ssl stuff(directory, docroot)] 

  ServerName account.example.com

  SSLEngine on

  SSLCertificateFile /Users/myusername/certs/server.crt

  SSLCertificateKeyFile /Users/myusername/certs/server.key

</VirtualHost>

<VirtualHost *:80>

  SSLEngine off

  [other stuff like docroot]

</VirtualHost>

Usage of a rewrite rule for redirecting from HTTP to HTTPS in HTTP vhost’s .htaccess file and now it works.

#Redirect from http to https

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

Related questions

0 votes
1 answer
asked Dec 9, 2020 in Azure by dante07 (13.1k points)

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer

Browse Categories

...