Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have Apache2 with one VirtualHost configured as following:

NameVirtualHost *:80
<VirtualHost *:80>
  ServerName gitlab.mydomain.com
  DocumentRoot /home/git/gitlab/public
  ProxyPass / http://127.0.0.1:9292/
  ProxyPassReverse / http://127.0.0.1:9292/

  ErrorLog  /var/log/apache2/gitlab/error.log
  CustomLog /var/log/apache2/gitlab/access.log combined
</VirtualHost>

It works for http://gitlab.mydomain.com. BUT it also works for all *.mydomain.com redirecting to the above defined VirtualHost.

How can I disable all the hosts besides the gitlab.mydomain.com, so that abc.mydomain.com will response with http 404?

Update:

Is it possible to do the same thing with 443? I have already a bad_url:

NameVirtualHost *:80
<VirtualHost *:80>
   DocumentRoot /var/www/bad_url
   ServerName *
</VirtualHost>

NameVirtualHost *:443
<VirtualHost *:443>
   DocumentRoot /var/www/bad_url
   ServerName *
</VirtualHost>

Now I get error on starting Apache:

Action 'start' failed.
The Apache error log may have more information.
 failed!

cat /var/log/apache2/error.log

[Wed Jul 31 03:09:05 2013] [error] Server should be SSL-aware but has no certificate configured [Hint: SSLCertificateFile] ((null):0)

I see the Hint, but is it possible without adding the SSL certificate?

share|improve this question
1  
You can use a dummy generated SSL certificate that you created on that server. A user would simply get a certificate error and then forward them to the bad url. –  kobaltz Jul 31 '13 at 3:16
add comment

1 Answer

up vote 1 down vote accepted

Try having a catch all that points to a http folder and has a simple index.html file that says that there was no server found here or something.

Also, if you're going to be serving gitlab, you may want to put this behind SSL.

NameVirtualHost *:80
<VirtualHost *:80>
   DocumentRoot /var/www/bad_url
    ServerName *
</VirtualHost>

<VirtualHost *:80>
  ServerName gitlab.mydomain.com
  DocumentRoot /home/git/gitlab/public
  ProxyPass / http://127.0.0.1:9292/
  ProxyPassReverse / http://127.0.0.1:9292/

  ErrorLog  /var/log/apache2/gitlab/error.log
  CustomLog /var/log/apache2/gitlab/access.log combined
</VirtualHost>

EDIT:

Your SSL is not working properly because you most likely do not have the SSLEngine module installed/on and not referencing to a SSL Certificate. Here is an example in my 443 connections.

   SSLEngine on
   SSLProtocol all -SSLv2
   SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM

   SSLCertificateFile /var/certs/cert.crt
   SSLCertificateKeyFile /var/certs/cert.key
   SSLCertificateChainFile /var/certs/gd_bundle.crt
share|improve this answer
    
ah, really, forgot about it at all. about gitlab and ssl - yep, will set it now. thank you! –  static Jul 31 '13 at 2:41
1  
Glad I could help! Had the same issue a few years back and was wondering WTF was going on. You would have come to the solution yourself if you had multiple servers running on the VirtualHosts and random subdomains kept pointing to the first available one. :) –  kobaltz Jul 31 '13 at 2:47
    
I'm wondering now, how can I do the same thing with another https site (443)? The same trick doesn't work. –  static Jul 31 '13 at 3:00
    
Can you edit your question with your new code? May be something as simple as adding the NamedVirtualHost *:443 and a virtualhost on :443 to do something similar. –  kobaltz Jul 31 '13 at 3:05
    
I thought - yes, should work as well. But apache doesn't start. Updated the code. –  static Jul 31 '13 at 3:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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