LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   What is the proper way to server multiple domain names with httpd? (https://www.linuxquestions.org/questions/linux-server-73/what-is-the-proper-way-to-server-multiple-domain-names-with-httpd-691776/)

nkoplm 12-19-2008 04:31 PM

What is the proper way to server multiple domain names with httpd?
 
I have a server in my basement that is currently serving a bunch of different websites for 3 TLDs. The only way I have ever known how to make this work is to add a bunch of these to the bottom of my httpd config file:

Quote:

NameVirtualHost 192.168.1.80:80
<VirtualHost 192.168.1.80:80>
ServerAdmin email-address@is.invalid
DocumentRoot /var/www/html/mysite.com
ServerName mysite.com
ErrorLog logs/error-log
CustomLog logs/access-log common
</VirtualHost>

NameVirtualHost 192.168.1.80:80
<VirtualHost 192.168.1.80:80>
ServerAdmin email-address@is.invalid
DocumentRoot /var/www/html/mysitestore
ServerName orders.mysite.com
ErrorLog logs/error-log
CustomLog logs/access-log common
</VirtualHost>

NameVirtualHost 192.168.1.80:80
<VirtualHost 192.168.1.80:80>
ServerAdmin email-address@is.invalid
DocumentRoot /var/www/html/myothercoolsite.com
ServerName www.myothercoolsite.com
ErrorLog logs/error-log
CustomLog logs/access-log common
</VirtualHost>
this seems to do the trick, but it is starting to get a bit messy with lots and lots of different sites starting to pile up at the end of my config file. Is there a cleaner or better way to do this?

also if it helps whenever i start the httpd service, i get these errors
[root@nethost root]# /sbin/service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[Fri Dec 19 13:53:22 2008] [warn] NameVirtualHost 192.168.1.80:80 has no VirtualHosts
[Fri Dec 19 13:53:22 2008] [warn] NameVirtualHost 192.168.1.80:80 has no VirtualHosts
[Fri Dec 19 13:53:22 2008] [warn] NameVirtualHost 192.168.1.80:80 has no VirtualHosts
[Fri Dec 19 13:53:22 2008] [warn] NameVirtualHost 192.168.1.80:80 has no VirtualHosts
[Fri Dec 19 13:53:22 2008] [warn] NameVirtualHost 192.168.1.80:80 has no VirtualHosts
[Fri Dec 19 13:53:22 2008] [warn] NameVirtualHost 192.168.1.80:80 has no VirtualHosts
[Fri Dec 19 13:53:22 2008] [warn] NameVirtualHost 192.168.1.80:80 has no VirtualHosts
[Fri Dec 19 13:53:22 2008] [warn] NameVirtualHost 192.168.1.80:80 has no VirtualHosts
[Fri Dec 19 13:53:22 2008] [warn] NameVirtualHost 192.168.1.80:80 has no VirtualHosts
[Fri Dec 19 13:53:22 2008] [warn] NameVirtualHost 192.168.1.80:80 has no VirtualHosts
[ OK ]
(one for each site)

billymayday 12-19-2008 04:37 PM

You don't need the "NameVirtualHost 192.168.1.80:80" before each VirtualHost. That may cause the error. Do you want to remove the text colouring so we can read that btw?

Depending on you distro, you may be able to separate your virtual definitions into /etc/httpd/conf.d or similar. Not quite sure I'd bother though.

Poetics 12-19-2008 06:41 PM

I have one single 'NameVirtualHost' entry followed by numerous VirtualHost sections, and it's been working fine for quite some time :)

I agree with Billymayday -- nix those NameVirtualHost entries (save for the first).

AuroraCA 12-19-2008 08:11 PM

Different distributions of Linux have different ways of implementing Virtual Hosts. Debian and derivatives use a separate /etc/apache2/sites-available directory in which separate individual virtual host files are maintained. A virtual host is enabled using the command:
Code:

a2ensite virtualsitefilename
(a2dissite disables a virtual host)

This command creates a link in the /etc/apache2/sites-enabled directory. When Apache2 is reloaded or started the configuration files are read from the /etc/apache2/sites-enabled directory to initialize the virtual hosts.

I prefer this implementation to the all in one httpd.conf file.


All times are GMT -5. The time now is 03:03 PM.