Create virtual host for services running on different ports
by Prabhat Rai

Posted on July 29, 2016 at 07:25 AM


Some services run on different ports and to access them in the browser we have to mention the port number also. For ex :


SonarQube : 9000 [http://127.0.0.1:9000]
Neo4j : 7474 [http://127.0.0.1:7474]
Jenkins : 8080 [http://127.0.0.1:8080]

It is difficult to remember different server IPs alone and now we have to remember the port number too. 😕

No need of remembering all this. We can use Apache’s mod_proxy module and can define the virtual host pointing to a specific port.


Just load the following config to apache.


ProxyRequests Off
ProxyPreserveHost On

<VirtualHost *:80>
    ServerName local.neo4j.com
    ProxyPass / http://127.0.0.1:7474/
    ProxyPassReverse / http://local.neo4j.com/
</VirtualHost>

We have defined a proxy and the process[Neo4j] will be running behind this proxy.


Note: Please make sure that you have proxy_module, proxy_html_module & proxy_http_module enabled in your apache config[httpd.conf].


For Nginx : 

Just load the following config :


server {
    listen 80;
    server_name local.neo4j.com;

    location / {
       proxy_pass http://127.0.0.1:7474;
    }
}

After loading these configs to server [Apache/Nginx] add the server name [local.neo4j.com] to your hosts file and browse http://local.neo4j.com, Voila, we see Neo4j server running.


UPDATE [04 August 2017]


Just found out another way to achieve this. Just add the following config in your httpd-vhosts.conf file.


<VirtualHost *:80>
ServerName local.neo4j.com
<Proxy *>
Allow from localhost
</Proxy>
ProxyPass / http://localhost:7474/
</VirtualHost>

Note: Please make sure that you have proxy_module, proxy_html_module & proxy_http_module enabled in your apache config[httpd.conf].


Hope this helps. 🙂



Share this

Search

  Recent Tips

See All »

  Recent Posts

  • Creating Installer for Laravel Project

    When you are working on a laravel project there is some basic setup that needs to be done for each install of the project. Like Permissions for ...

  • Laravel Queues With Supervisor

    In this blog, we are going to take a look into Laravel Queues. Queues allow you to defer the processing of a time-consuming task, such as sending a...

  • Partials & Utils in Handlebars

    PARTIALS Let’s say we have a structure like the following : data = { students : [{ name : ‘ABC’, roll : 1 }, { name : ‘DEF&...

See All »

  Recent Seminars

  • PHP 8 - Features

    PHP 8 has been officially released in November 2020! This new major update brings many optimizations and powerful features to the language. This...

  • ProxySQL

    ProxySQL is a high-performance SQL proxy. ProxySQL runs as a daemon watched by a monitoring process. The process monitors the daemon and restarts i...

  • Unix Commands & Shell Scripts to help save our time

    Time is important. We should not waste it doing trivial things. Automate things wherever possible.

See All »