1
votes

How to create a virtual host in cent os?

I have change some in /etc/httpd/conf/httpd.conf file

<VirtualHost local.mydomain.com>
ServerAdmin [email protected]
DocumentRoot /var/www/html/test/
ServerName local.mydomain.com
ServerAlias local.mydomain.com
</VirtualHost>

and in /etc/hosts file

127.0.0.1       dexs01 localhost.localdomain6 localhost #existing lines
::1             localhost6.localdomain6 localhost #existing lines
127.0.0.1       local.mydomain.com       local.mydomain.com #my addition

and then I restarted my Apache server so what wrong in this?

1
the best thing to do in this case is to check the apache logs, in most cases it will tell exactly what the problem is if it's something in the httpd.conf file - Yehia A.Salam
Also, it's good to maybe mention what actually happens when you hit your domain in the browser. - muffinista

1 Answers

0
votes

you have to define in the VirtualHost directive the IP and the port:

<VirtualHost *:80>
  ...
  ServerName local.mydomain.com
  ...
</VirtualHost>

the rest looks good.
note: in your case you do not need the ServerAlias directive because it matches your ServerName.