Search code examples
apachevirtualhost

Run multiple web apps on the same ip


Let's assume I have Apache HTTP Server, an ip address and I don't any domain names. My question is how to run two web apps on the same ip but different ports.
For example:

  • App_1 runs on ip_address:port_1
  • App_2 runs on ip_address:port_2

So I can access both of by typing ip address and port number in address line of browser. As I understand it's called IP-based virtual hosts.


Solution

  • In the httpd.conf filr in Apache/conf you have to create VirtualHosts like below:

    Listen 80
    Listen 81
    <Directory />
        AllowOverride none
        Require all granted
    </Directory>
    <Directory /var/www>
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
    <VirtualHost IPAddress:80>
        ServerName localhost:80
        WSGIScriptAlias / "C:/var/www/GP/GP/wsgi.py"
        Alias /static/ "C:/var/www/GP/static/"
        Alias /templates/ "C:/var/www/GP/templates/"
        <Directory "C:/var/www/GP/static">
            Require all granted
        </Directory>
        <Directory "C:/var/www/GP/GP">
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>
    </VirtualHost>
    <VirtualHost IPAddress:81>
        ServerName localhost:81
        WSGIScriptAlias / /var/www/adminSVNProject/adminSVNProject/wsgi.py
        Alias /static/ /var/www/adminSVNProject/static/
        Alias /templates/ /var/www/adminSVNProject/templates/
        <Directory /var/www/adminSVNProject/static>
            Require all granted
        </Directory>
        <Directory /var/www/adminSVNProject/adminSVNProject>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>
    </VirtualHost>
    WSGIPythonPath /var/www/GP;/var/www/adminSVNProject;
    

    If your files are in C:var/www
    Hope it helps you.