Redirect to a port number depending on the URL


My server has 3 websites :

  • Gitlab running with Omnibus on port 80
  • React.js application in a Docker on port 3001
  • Jorani (php application) on Apache on port 8008

Since DNS can't handle the port number, how may I redirect to a port depending on the URL the user gives, for example :

I saw some post about Proxy or reverse proxy but i'm not sure if it's the good way to proceed


So here is the solution I'm using :

I changed my gitlab port to 8900. I changed my Apache port to 80.

I'm now using virtualhosts with Apache :

For CentOS 7 in /etc/httpd/sites-available/

gitlab.conf :

<VirtualHost gitlab.mydomain.intra:80 >
        ServerName gitlab.mydomain.intra
        ProxyPreserveHost On
        ProxyRequests On
        ProxyPass / http://localhost:8900/
        ProxyPassReverse / http://localhost:8900/

react.conf :

<VirtualHost react.mydomain.intra:80 >
        ServerName react.mydomain.intra
        ProxyPreserveHost On
        ProxyRequests On
        ProxyPass / http://localhost:3001/
        ProxyPassReverse / http://localhost:3001/

jorani.conf :

<VirtualHost jorani.mydomain.intra:80 >
        ServerName jorani.mydomain.intra
        ProxyPreserveHost On
        ProxyRequests On
        ProxyPass / http://localhost:80/jorani
        ProxyPassReverse / http://localhost:80/jorani

Problem : I can't manage to make it work for gitlab with SSL (gitlab.mydomain.intra => https://gitlab.mydomain.intra/). Will post the solution if I find it.

EDIT : Here is the solution for gitlab with https :

/etc/gitlab/gitlab.rb :

external_url ''
nginx['enable'] = true
nginx['redirect_http_to_https'] = true
nginx['listen_addresses'] = ['localhost']
nginx['listen_port'] = 8888
nginx['listen_https'] = false


<VirtualHost gitlab.mydomain.intra:80>
    ServerName gitlab.mydomain.intra
    ErrorLog /var/log/httpd/gitlab.mydomain.intra/error.log
    Redirect 301 / https://gitlab.mydomain.intra/
<VirtualHost gitlab.mydomain.intra:443>
    ServerName gitlab.mydomain.intra
    ErrorLog /var/log/httpd/gitlab.mydomain.intra/error.log
    RequestHeader set Host "gitlab.mydomain.intra"
    #RequestHeader add X-Forwarded-Ssl on
    #RequestHeader set X-Forwarded-For %<span class="pl-s1"><span class="pl-pse">{</span>REMOTE_ADDR<span class="pl-$
    #RequestHeader set X-Forwarded-Proto "https"

    ProxyPreserveHost On
    ProxyPass / http://localhost:8888/
    ProxyPassReverse / http://localhost:8888/

    SSLEngine On
    SSLCertificateFile /etc/gitlab/ssl/gitlab.mydomain.intra.crt
    SSLCertificateKeyFile /etc/gitlab/ssl/gitlab.mydomain.intra.key

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at


Login to comment


Remove port number from a url in java

Stripe Redirect URI - Dynamic number in url

Find serial number and redirect to appropriate url

Conditional redirect in .htaccess depending on the number of path segments in the URL

Avoiding port number in Liferay's assets URL

Complete Regex to match url with port number

HTTPS url with port number not working on iOS

forward the domain and remove the port number from the URL

how to redirect a url with port via htaccess

How to redirect to Tomcat depending on _escaped_fragment_ in the URL?

Validate URL with valid port number and query string

Nginx Redirect depending on URL Param

Port number getting stripped out of URL

Get URL and port number from view

Permanent Redirect huge number of url-s via .htaccess or php

Regex optionally match port number in url

Can URL contain colons to represent a value other than port number

Nginx remove port number :8080 in the url

redirect 301 depending on parameter

Android - Forming an URL object specifying a port number

Udev rule to alias device depending on USB port number

HTACCESS: Redirect to home page if invalid number in url

Redirect traffic to a domain with a port number without showing the port number in the URL

How to connect url with port number in java with Jsoup?

nmap or ping a url with embedded port number?

Remove port number in image url?

Ingress SSL redirect with port number not replacing https port number

Traceroute number of hops changes depending on the tcp port used

Trying to redirect a page depending on what is in the URL with Javascript

TOP Ranking