skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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/
    </VirtualHost>
    

    react.conf :

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

    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
    </VirtualHost>
    

    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 'https://gitlab.mydomain.com/'
    nginx['enable'] = true
    nginx['redirect_http_to_https'] = true
    nginx['listen_addresses'] = ['localhost']
    nginx['listen_port'] = 8888
    nginx['listen_https'] = false
    

    /etc/httpd/sites-available/gitlab.conf

    <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>
    <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
    </VirtualHost>
    

  2. In the publicly-accessible internet, HTTP traffic should be over port 80 (or over TLS that runs on port 443 for HTTPS). You can theoretically have HTTP on any port, but that is very bug-prone and not all machines support that, so it’s discouraged in production. As such you should not redirect traffic from subdomain.domain.extension to domain.extension:port.

    Instead, you have two solutions:

    The three servers run behind three IPs: each subdomain has an IP address. Each server runs behind its own IP. Your DNS server should send records for each of these domain name – IP address associations.

    Reverse proxy: each subdomain goes to the same IP. Behind this IP runs a fourth server – the proxy. Its simple task is to look at the subdomain in the path and re-route the HTTP(S) traffic to the corresponding applications that it is connected to (gitlab, react, or jorani). Note that none of these three applications are directly accessible from the public internet.

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