1

In apache, I would like to setup "ip-based" hosting for 2 sites and enable SSL for them. However, I'm not clear on how to configure httpd.conf file.

Questions:

1) Do I need a NameVirtualHost directive for ip-based setup? On Apache's site, it say it's required for name-based but there's no mention of ip-based.

2) If NameVirtualHost required, must the number of description and quantity match the number of VirtualHost directives? Example, can I say "NameVirtualHost *:80" and later use and ? Or, will I need "NameVirtualHost IP_ADDRESS_1:80" and "NameVirtualHost IP_ADDRESS_2:80"

3) If ServerName were example1.com (without "www"), would it make a difference??

4) In VirtualHost, do I need to set a value for ServerAlias, such as the IP itself?

One thing I'll to share is if you have (and likely including) ssl.conf, you should not add "Listen 443" to your httpd.conf, otherwise upon reload, apache will throw a "Address already in use: make_sock: could not bind to address [::]:443" error.

#see above questions about below directive
#NameVirtualHost *:80
#NameVirtualHost *:443  
...
<VirtualHost IP_ADDRESS_1:80>
  DocumentRoot /www/example1
  ServerName www.example1.com
</VirtualHost>

<VirtualHost IP_ADDRESS_2:80>
  DocumentRoot /www/example2
  ServerName www.example2.org
</VirtualHost>

<VirtualHost IP_ADDRESS_1:443>
  DocumentRoot /www/example1
  ServerName www.example1.com

  SSLEngine on
  SSLProtocol all
  SSLCertificateFile /home/web/example1_certs/public.crt
  SSLCertificateKeyFile /home/web/example1_certs/private.key
  SSLCACertificateFile /home/web/example1_certs/intermediate.crt
</VirtualHost>

<VirtualHost IP_ADDRESS_2:443>
  DocumentRoot /www/example2
  ServerName www.example2.org

  #yes, in below, I'm using example1.com's certificate, which will throw a browser warning.. that's intentional
  SSLEngine on
  SSLProtocol all
  SSLCertificateFile /home/web/example1_certs/public.crt
  SSLCertificateKeyFile /home/web/example1_certs/private.key
  SSLCACertificateFile /home/web/example1_certs/intermediate.crt
</VirtualHost> 

1 Answer 1

1
  1. No you just need the vhost with the IP as in your example
  2. N/A
  3. No it wouldn't matter
  4. It depends if you want to host multiple domains on that IP.
4
  • Thank you, Lucas! I'm moving name-based to ip-based and current it has "ServerAlias IP_ADDRESS_1", so it sounds like I should omit that line, otherwise it's redundant? Apr 21, 2012 at 16:30
  • Yes, it is. There is no reason to use that anymore since you have split things up with IP's. Apr 21, 2012 at 16:43
  • Worked flawlessly this morning updating the production server. Many thanks, Lucas!!! Apr 22, 2012 at 11:30
  • Glad I could help :) Apr 22, 2012 at 11:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .