apache2 - ServerName in virtual host isn't working

296 Views Asked by At

That is my first time configuring the virtual host for local work and tests in my computer. I'm trying to access the blog.dev that I configurate on sites-available/default, but it isn't working. Here's my sites-available/default:

<VirtualHost *:80>
    ServerAdmin [email protected]

    ServerName blog.dev
    ServerAlias www.blog.dev
    DocumentRoot /var/www/crud/public
    <Directory />
            Options FollowSymLinks
            AllowOverride All
    </Directory>
    <Directory /var/www/crud/public>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride All
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

I did the sudo a2ensite blog.dev.conf and sudo service apache2 restart. According to the guides, helps and tutorials that I found, it should be running. But my browser can't find the http://blog.dev .
When I type localhost, it still works, but the ServerName isn't working. The NameVirtualHost *:80 is ok on ports.conf.
I tried configuring a new file called blog.dev.conf in the sites-available/ directory, but it still not working.

2

There are 2 best solutions below

1
On BEST ANSWER

If blog.dev isn't a real domain and you don't have a DNS entry pointing to your server then you will need to add a fake entry into your system's hosts file so the domain name can be resolved.

Under windows you can add the entry to the hosts file located here: c:\windows\system32\drivers\etc\hosts

Then as THEcreationist said, add 127.0.0.1 blog.dev on a line by itself.

For linux environments see THEcreationist's response.

By the sounds of it that should fix your problem.

0
On

You need to put the following entry in your /etc/hosts file:

127.0.0.1    blog.dev