skip to Main Content

I have a server with apache(2.4.18) installed

I have installed multiple applications on the server like Grafana, Sonarqube, and MySQL enterprise monitor(MEM)

Each application has URL like this

http://test.com:9000

http://test.com:3000

I am looking for a solution which allows me to redirect this URL with the port to URL with context, something like that

http://test.com:9000  --> http://test.com/sonar

http://test.com:3000 --> http://test.com/grafana

I have added some code in /etc/apache2/sites-enabled/000-default.conf file

Redirect permanent /sonar http://test.com:9000

Redirect permanent /grafana http://test.com:3000

but when I enter http://test.com/sonar in the web browser it redirects to http://test.com:9000 URL only

I want http://test.com/sonar this URL to persists on Web browser

2

Answers


  1. You need to proxy requests and not redirect them.
    Use a ProxyPass directive as mentioned in the official apache proxy documentation

    For example add this location block inside your configuration:

    <Location "/sonar">
        ProxyPass "http://test.com:9000"
    </Location>
    
    Login or Signup to reply.
  2. If you use Redirect permanent, server will send 301 response back to client (along with new Location). That will result in browser issuing a new request, this time to new Location, and also new location will be shown in browser address bar.
    What you need is Reverse Proxy. For this you need to make sure that mod_proxy is enabled in your apache configuration (usually it is enabled by default), and put something like this in your .conf file:

    ProxyPreserveHost On
    ProxyPass        /sonar   http://127.0.0.1:9000
    ProxyPassReverse /sonar   http://127.0.0.1:9000
    ProxyPass        /grafana http://127.0.0.1:3000
    ProxyPassReverse /grafana http://127.0.0.1:3000
    

    You will probably also have to make your applications aware that they are running under non-root context (by making some configuration changes):

    http://docs.grafana.org/installation/behind_proxy/

    https://docs.sonarqube.org/latest/setup/install-server/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search