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>
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
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 belocalhost
and for the grafana site theServerName
would begrafana
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 tolocalhost
. Apache will know to use the virtual host file that usesgrafana
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.