-2

I have a centos server, but I am having some issue regarding port 443 and ssl. my problem is that all domain on my server are accessible from HTTPS port.

like when I visit a domain on my server from HTTPS, which do not have ssl, then it shows default host page (default apache page)

I want only domain which I specified should only use ssl port.

I have certificate for a domain, and I have added virtual host like this:

<VirtualHost *:80 *:443>
    ..
    ..
     ServerName domain.com
     ServerAlias www.domain.com
     ErrorLog ...
     CustomLog ...
</VirtualHost>

and other certificate file locations are specified in /etc/httpd/conf.d/ss.conf

I also tried creating 2 separate with port 80 and 443, but still it does not help in my case. still if i visit other domain with HTTPS, i see default Apache page.

Thanks for help

user007
  • 103
  • 5

1 Answers1

2

you might want to try this:

<VirtualHost *:80>
  ServerName www.domain.com
  ServerAlias domain.com

  // non ssl config

  RewriteEngine on
  RewriteRule ^/(.*)$ https://www.domain.com/$1 [L,R=301]
</VirtualHost>
<VirtualHost *:443>
  ServerName www.domain.com
  ServerAlias domain.com

  // your ssl configuration etc

  RewriteEngine on
  RewriteCond %{HTTP_HOST} !^www.domain.com
  RewriteRule ^/(.*)$ https://www.domain.com/$1 [L,R=301]
</VirtualHost>

this should redirect all requests to www.domain.com no matter what other domain the user used. if you want to preffer domain.com over www.domain.com move the www. from ServerName and the Rewrite statements and add it to the ServerAlias.

the rewrite in *:80 redirects your www.domain.com to the https site and the rewrite in *:443 ensures that your request goes to https://www.domaincom

Dodge
  • 218
  • 3
  • 7