Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

closed as off-topic by MadHatter, Iain, mdpc, Jenny D, Ward Jun 5 at 4:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must demonstrate a minimal understanding of the problem being solved. Try including attempted solutions, why they didn't work, and the expected results. See How can I ask better questions on Server Fault? for further guidance." – MadHatter, Iain, Ward
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
you should use two <VirtualHost> blocks. one for *:80 an done for *:443 and configure your ssl only in th *:443 block. –  Dodge Jun 3 at 6:48
    
Tried that too, but same thing happen –  user007 Jun 3 at 6:52
    
possible duplicate of Two domains (when SSL) on same directory –  Jenny D Jun 4 at 8:28
    
No its not duplicate, i have different issue –  user007 Jun 4 at 8:30

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
Thanks friend, let me give it a try –  user007 Jun 3 at 7:12
    
It solved my issue. thanks –  user007 Jun 4 at 8:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.