-4

I have followed this guide https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-6

I have a website in /var/www/html. I followed the guide and i have the main site setup as the first virtual host. I can access the website fine so i havnt broken it. I have added the following to the bottom of /etc/httpd/conf/httpd.conf

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot "/var/www/html"
</VirtualHost>

I want to be able to add some prefix domains. m.example.com, forum.example.com etc. To test this i have tried setting up a second virtual host for the same directory but with a different server name. This should link to the same website, but instead i get a page cannot be displayed error with the following "ERR_NAME_NOT_RESOLVED"

<VirtualHost *:80>
    ServerName m.example.com
    DocumentRoot "/var/www/html"
</VirtualHost>

I have set the following 2 variables in the httpd.conf file

ServerName www.example.com:80
NameVirtualHost *:80
1
  • So I should set these with go daddy? Like forum.example.com goes to the main site and then apache does the rest? Commented Jan 30, 2015 at 12:58

2 Answers 2

5

You need to add DNS records for the new vhosts. This is done wherever your authoritative DNS service for this domain is hosted.

2
  • So I need to make a new cname alias? This this point to the main domain? So host = forum, points to = example.com? Commented Jan 30, 2015 at 14:20
  • Yes, that sounds right.
    – EEAA
    Commented Jan 30, 2015 at 14:23
1

DNS is a long term solution, short term for testing you could just add this to your hosts file on the computer where you're running your browser.

Windows: C:\Windows\System32\drivers\etc\hosts (using notepad or something similar running as Administrator)

Linux: /etc/hosts as root

Then add a new line to it

[server IP address] m.example.com www.example.com

for example

127.0.0.1 m.example.com www.example.com

Then after saving you should be able to refresh your browser and see the website.

What this will do is basically setup a local "DNS" entry which your browser will use when trying to resolve the domain.

You must log in to answer this question.

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