Thursday, January 8, 2015

virtualhost - Apache ip-based hosting setup and httpd.conf directives




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
...

DocumentRoot /www/example1

ServerName www.example1.com



DocumentRoot /www/example2
ServerName www.example2.org



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




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



Answer




  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.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...