Virtual hosts

Support for webhosts that use CentOS
Post Reply
tomitzel
Posts: 1
Joined: 2012/10/26 09:44:38

Virtual hosts

Post by tomitzel » 2012/10/26 09:51:38

Hello,

I have a server with IP 1.2.3.4 and I want the domain www.something.com to load website from /var/www/html/something/

I've tried to configure them as follows:
NameVirtualHost 1.2.3.4:80



ServerName www.something.com
ServerAdmin emai@email.com
DocumentRoot /var/www/html/something/
ErrorLog logs/something-error_log
CustomLog logs/something-access_log common


I've reloaded apache, but when accesing the domain, it only shows the root of the server /var/www/html/

Any idea what is wrong?

MIKNOTAURO
Posts: 1
Joined: 2012/10/26 11:36:20

Re: Virtual hosts

Post by MIKNOTAURO » 2012/10/26 11:57:09

you have to make this
type on /etc/httpd/
mkdir sites-available
mkdir sites-enabled

then you have to edit

conf/httpd.conf


something like this

NameVirtualHost *:80
Include /etc/httpd/sites-enabled/

then you have to create some configuration files for your sites

[root@mik httpd]# cd sites-available/
[root@mik sites-available]# cat > something.com.vhost.conf
#
# something.com (/etc/httpd/sites-available/something.com)
#

ServerAdmin admin@something.com
ServerName something.com
ServerAlias www.something.com *.something.com

#Indexes + Directory Root
DocumentRoot /home/csmith/www/something.com/htdocs/

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all


#LOG FILES
ErrorLog /home/csmith/www/something.com/logs/error.log
CustomLog /home/csmith/www/something.com/logs/access.log combined


Change the DocumentRoot to wherever you want

[root@mik sites-available]# ln -s /etc/httpd/sites-available/something.com.vhost.conf /etc/httpd/sites-enabled/something.com.vhost.conf

restart your service... and thats all...

User avatar
TrevorH
Forum Moderator
Posts: 26886
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Virtual hosts

Post by TrevorH » 2012/10/26 14:15:29

Most of that looks like Debianisms and will most likely not work in CentOS.

Vhost files are best created in /etc/httpd/conf.d as that needs no modification of the distro supplied httpd.conf to be picked up.

Under CentOS with selinux turned on as default, httpd will be unable to access /home/ directories without special action.

[b]tomitzel[/b] Creating your vhost under /var/www/html/subdir means that the default web site can access the other site's data by using e.g. http://default.web.site/something which may not be what you desired. I find it better to create a /var/www/something site which is one level up from the default docroot and thus can't be seen from the default site yet still picks up the correct selinux contexts. The server needs to be able to lookup www.something.com and resolve it to the IP address that you have given in the virtual host definition - can it do that?

Post Reply

Return to “CentOS 5 - Webhosting Support”