1

I have multiple web project on my localhost Ubuntu 14.04 VM which i am trying to run using apache2.

When i open my web browser and go to http://localhost:80 it will load apache2-graphite.conf When i try to load localhost:80/grafana from my web browser it would still load apache2-graphite.conf but not grafana.conf ? I am trying to display my grafana website which is stored at /var/www/grafana/public_html. Can someone explain why does it always load apache2-graphite.conf

Below are the commands/files i am attaching

sudo a2ensite apache2-graphite
sudo a2ensite grafana
sudo service apache reload

root@marshell:vi /etc/apache2/sites-available/apache2-graphite.conf

<VirtualHost *:80>

        WSGIDaemonProcess _graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120 user=_graphite group=_graphite
        WSGIProcessGroup _graphite
        WSGIImportScript /usr/share/graphite-web/graphite.wsgi process-group=_graphite application-group=%{GLOBAL}
        WSGIScriptAlias / /usr/share/graphite-web/graphite.wsgi

        Alias /content/ /usr/share/graphite-web/static/
        <Location "/content/">
                SetHandler None
        </Location>

        ErrorLog ${APACHE_LOG_DIR}/graphite-web_error.log

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

        CustomLog ${APACHE_LOG_DIR}/graphite-web_access.log combined

</VirtualHost>

root@marshell: vi /etc/apache2/sites-available/grafana.conf

<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        ServerName grafana
        ServerAlias www.127.0.0.1:80/grafana
        DocumentRoot /var/www/grafana/public_html


        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
1

Two ways to fix the problem.

1. Use an Alias

With this method you only have one virtual host file and define an alias for your secondary site. An Alias will point to a different directory when you specify the Alias in the url. In this case the url: localhost/grafana will take you to your grafana site.

A simplified version of your virtual host files would look like

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    ServerName localhost

    DocumentRoot /var/www/defaultSite

    <Directory /var/www/defaultSite>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

    Alias /grafana  /path/to/grafana
    <Directory /path/to/grafana>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

2. Separate virtual host file and edit client hosts file

You can also define different virtual hosts files and use the ServerName parameter to decide which one to serve. In this configuration Apache looks at the hostname part of the url. So you need to change the client so that you can use a different url to get to it. So you would have two virtual host files like the one above MINUS the Alias stuff. In the default site the ServerName would be localhost and for the grafana site the ServerName would be grafana

Then on your client (which is also the server here) you need to edit /etc/hosts and add the line:

127.0.0.1 grafana

Now the url http://grafana will point to localhost. Apache will know to use the virtual host file that uses grafana as the ServerName and the correct site will be served.

I prefer the Alias method because it is so easy to add a new one at any time. The clients do not need to be edited to access the site.

However the ServerName option make the url a little cleaner, but every client needs to have their hosts file updated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.