Redirect subdomain to specific port

Discussion in 'General' started by fossoffice, Nov 28, 2013.

  1. fossoffice

    fossoffice New Member

    [SOLVED] Redirect subdomain to specific port

    Hi there!
    First post, congrats for your work!

    I'd like to redirect a subdomain to a non-apache application that works on a specific port. Let's say:
    Code:
    http://sub.domain.com => http://domain.com:9090
    For this, I found that the ProxyPass functionality in apache is exactly what I need. So (after adding the appropriate A Record), according to this I added this text to my site's vhost:
    Code:
    <Directory /var/www/domain.com>
                    AllowOverride None
                    Order Deny,Allow
                    Deny from all
    </Directory>
    <VirtualHost xxx.xxx.xxx.xxx:80>
                    DocumentRoot /var/www/domain.com/web
                    ServerName domain.com
                    ServerAlias www.domain.com 
    [...]
    </VirtualHost>
    [B]<VirtualHost xxx.xxx.xxx.xxx:80>
      ServerName sub.domain.com
      ProxyPass        /       http://localhost:9090/
    </VirtualHost>[/B]
    and I became happy. For a while...
    The thing is that after a period of time ISPConfig overwrites my vhost according to its settings and the desired functionality is lost. I find this a normal situation, yet it ruins my plans.
    Is there a way for this functionality to exist in conjunction with ISPConfig? Is anybody aware of another way to do it?
    I use ISPConfig 3.0.5.3 on top of an Ubuntu 12.04 LAMP server, built using your REALLY PERFECT tutorial.

    Thanx in advance!
     
    Last edited: Nov 28, 2013
  2. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    I would create an additional vhost file for this. Name it like the one ISPConfig creates and append a -2 at the end (in front of the extension).
     
  3. fossoffice

    fossoffice New Member

    Thank you for your instantaneous reply!
    I tried this with no luck. Now when I try http(s)://sub.domain.com/ it redirects to http(s)://www.domain.com/. http://domain.com:9090/ is working. Here is my domain.com-2.vhost file:
    Code:
    <VirtualHost xxx.xxx.xxx.xxx:80>
      ServerName sub.domain.com
      ProxyPass               /       http://localhost:9090/
    </VirtualHost>
     
  4. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    Maybe you have auto-subdomain to * in ISPConfig for the main domain or added a subdomain there?
     
  5. fossoffice

    fossoffice New Member

    No, I had "www", but even with "None" or "*." the result is the same.
    All tests performed after resyncing in ISPConfig, restarting apache and clearing browser's cache.
    Could this be a bug?
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    Its very unlikely that this is a bug, because when the vhost works when you created it in ispconfig and then added a proxy directive, then the same vhost must work when you create it manually by using the same config file.
     
  7. fossoffice

    fossoffice New Member

    Yes, that's my "sense" too.
    Nevertheless, during the last couple of hours I am playing with the vhosts and the only way for the subdomain to be redirected to the desired port is to "nail" it, as described above, to the main site's vhost (as long as it is not resynced by ISPConfig). Every other attempt leads me to redirection to www (while the application is still accessible at its port).
    I'll keep testing for a while before I decide to put something in front of apache (I'd like to avoid this).
     
  8. fossoffice

    fossoffice New Member

    Ok, I found the solution!
    I tried to "cheat" ISPConfig through the site's "Apache Directives". And it works!

    So here is the whole procedure for everyone in my position:

    At first, we file an A Record for our subdomain at our site's DNS zone, pointing to our IP.
    Then we go to Sites=>domain.com=>Options=>Apache Directives and we add this AT THE END of our directives:
    Code:
    # CAUTION: Do not write anything below.
    # If you want to add another directive, please add it above this.
    </VirtualHost>
    
    <VirtualHost xxx.xxx.xxx.xxx:80>
      ServerName sub.domain.com
      ProxyPass  /  http://localhost:9090/
    replacing "xxx.xxx.xxx.xxx" with our actual IP (or "*" depending on our site's settings).
    We resync our sites and DNS records (Tools=>Resync), we clear our browser's cache to be safe, and we're ready! Now we can reach our application, that was previously serving at the non-human http://domain.com:9090/, to http://sub.domain.com/.
    We must be very careful to position those "directives" at the right place. Thus, we make this addition at the end of our existing directives (if any). And, in the future, if we have to add some more, we add them above this text (as mentioned in the commented section).

    Thank you guys for your attention and your beautiful software!

    K.
     
  9. Ark74

    Ark74 Member

    I'll like to achieve something similar, i would like to redirect some domain to another port (else 80) let's say 85.

    sub.domain.com -> sub.domain.com:85

    I've tried using .htaccess but no luck with it.
    Found this thread and it hits the head of the nail, but i tried on a *buntu 14.04 / Apache2 / ISPConfig3 and no luck so far.

    Any further advice?
     

Share This Page