How to add another application to apache?

5,182

Solution 1

You have a couple of options; 1: putting zabbix on a different port; 2: making it accessible under the normal vhost.

For #1 update 000-default to:

DocumentRoot /home/zabbix/public_html

AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Order allow,deny Allow from all Order deny,allow Deny from all

For #2

Move 000-default to /etc/apache2/conf/zabbix.conf and add :

Include /etc/apache2/conf/zabbix.conf

above the similar Include statement in /etc/apache2/sites-enabled/railsapp

Solution 2

You will need to tell Apache to listen on an extra port and then set your Rails application's configuration to use a different NameVirtualHost port.

Judging by the configuration information you have provided there will be three Listen parameters in your Apache configuration:

Listen *:80
Listen *:443
Listen *:8080

These maybe spread across a few configuration files depending on how Apache is configured. You want to add a fourth port to listen to for your Rails app, for example 8081:

Listen *:80
Listen *:443
Listen *:8080
Listen *:8081

Once this extra Listen directive is in place edit the /etc/apache2/sites-enabled/railsapp file and change the first NameVirtualHost directive to 8081, for example:

NameVirtualHost *:8081
NameVirtualHost *:443
....

Restart Apache and you'll find zabbix on 80, the Rails app on 8081/443 and Mercurial on 8080.

However....

If you can set DNS records within your internal network (I am guessing this is for internal use) you can setup virtual hosts that are differentiated by domain name rather than port. Apache would then only need to listen to the default ports 80 and 443 and you would differentiate between applications using the domain url, for example:

zabbix.yourdomain.com
railsapp.yourdomain.com
mercurial.yourdomain.com

The benefit of this is that you can continue adding different virtual hosts without having to use a new port each time. There are plenty of documents on the web explaining how to set this up (hint: see the Ubuntu documentation).

The only caveat to this approach is that only one virtual host can process HTTPS requests on a specific port (443) due to the way the protocol works. However, if you only need HTTPS access to one of the virtual hosts this isn't a problem, just don't tell the other hosts to use HTTPS (443) and you'll be fine.

Share:
5,182

Related videos on Youtube

Jader Dias
Author by

Jader Dias

Updated on September 17, 2022

Comments

  • Jader Dias
    Jader Dias over 1 year

    I was following the Zabbix installation tutorial for Ubuntu and it requested that I added a file /etc/apache2/sites-enabled/000-default containing

    Alias /zabbix /home/zabbix/public_html/
    <Directory /home/zabbix/public_html>
      AllowOverride FileInfo AuthConfig Limit Indexes
      Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
      <Limit GET POST OPTIONS PROPFIND>
        Order allow,deny
        Allow from all
      </Limit>
      <LimitExcept GET POST OPTIONS PROPFIND>
        Order deny,allow
        Deny from all
      </LimitExcept>
    </Directory>
    

    But I already have /etc/apache2/sites-enabled/railsapp

    NameVirtualHost *:80
    NameVirtualHost *:443
    
    <VirtualHost *:80>
        UseCanonicalName Off
        Include /etc/apache2/conf/railsapp.conf
    </VirtualHost>
    
    <VirtualHost *:443>
        SSLEngine on
        SSLCertificateFile /etc/ssl/certs/cert.pem
        Include /etc/apache2/conf/railsapp.conf
        RequestHeader set X_FORWARDED_PROTO 'https'
    </VirtualHost>
    

    and /etc/apache2/sites-enabled/mercurial

    NameVirtualHost *:8080
    
    <VirtualHost *:8080>
        UseCanonicalName Off
        ServerAdmin  webmaster@localhost
        AddHandler cgi-script .cgi
        ScriptAliasMatch ^(.*) /usr/lib/cgi-bin/hgwebdir.cgi/$1
    </VirtualHost>
    

    I think that it is because of the already existing virtual hosts that my I can't access the zabbix page. How to circumvent this?

    • Philip
      Philip about 14 years
      Looks like normal stuff. Are you getting an error, or is something not working?
    • Jader Dias
      Jader Dias about 14 years
      @Chris I can't access the /zabbix site on port 80 because it is assigned to the /etc/apache2/sites-enabled/railsapp app. I would like to put zabbix on another port, so it doesn't conflict with railsapp. I don't know how to do it.
  • Jader Dias
    Jader Dias about 14 years
    I could implement suggestion #2 only, so far.
  • Jader Dias
    Jader Dias about 14 years
    I used Listen *:8081 and NameVirtualHost *:8081 in my current solution