These forums are read-only!
Redirect/Hide port number in URL
  • Hi,

    I have two apache servers running on ports 80 and 8080. They both work, but I'd like the URL to not show 8080, and also use the subdomain like this:

    port 80 apache ==> http://www.mydomain.com

    port 8080 apache ==> http://beta.mydomain.com

    The problem I'm having right now are:

    (1) If I just type http://beta.mydomain.com, the contents are the same as http://www.mydomain.com
    (2) I have to type http://beta.mydomain.com:8080 or http://www.mydomain.com:8080 in order to access apps running on port 8080

    Does anyone know how to make this happen? Does this have to be done on a DNS level? If so, how would I forward a beta.mydomain.com request to port 8080?
    Below are my vhost files.
    Thanks!

    ============= My vhost configs ==============

    - Contents of /etc/apache2/sites-available/www.mydomain.com:


    ServerName mydomain.com
    ServerAlias www.mydomain.com
    DocumentRoot /var/www/html

    AllowOverride AuthConfig
    ...

    # Turn on/off Rewrite Engine
    RewriteEngine on
    # force mydomain.com to go to www.mydomain.com
    RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
    RewriteCond %{HTTP_HOST} !^beta\.mydomain\.com [NC]
    RewriteCond %{HTTP_HOST} !^$
    RewriteRule ^/(.*) http://www.mydomain.com/$1 [L,R]


    - Contents of /etc/apache2-beta/sites-available/beta.mydomain.com:


    ServerName beta.mydomain.com
    RailsEnv test
    DocumentRoot /var/www/html_beta

    AllowOverride AuthConfig
    ...
  • >> I have to type
  • Thanks, artagesw.. I know I can run as many vhosts as I like on port 80. However, I'm trying to run two sites in parallel, one production and one beta, and I need to be able to restart apache without affecting one another. That's the reason for my two apache servers on two different ports. (Unless, of course, I'm missing something here.. ) It wouldn't be the end of the world, if I (and the testers) had to always type 8080 in the URL for beta site. But I thought there must be a way, and started looking around. Haven't found a way yet, and thought I'd ask the experts here. :-)
  • You'd have to put in a support request for a second public IP address for your slice. Then you have one instance of Apache listening on port 80 on IP address A, and the second instance of Apache would listen on port 80 on IP address B. In both Apache config files, you'd have to explicitly specify the IP addresses, since otherwise Apache will try to listen on all available interfaces.
  • You might consider setting up mod_proxy on the main Apache instance that proxies beta.example.com:80 to localhost:8080, which is served by the second Apache instance. This setup will allow you to restart that one whenever you want without affecting the production site while also not having to remember to add a port number in your URLs.

    But really, you should probably just set up a separate development/staging server so you don't have to worry about this stuff.
  • bq. ??kwilson?? But really, you should probably just set up a separate development/staging server so you don't have to worry about this stuff.

    Yep, if you're truly trying to simulate your production environment, that's the way to go. If your current two-Apache setup uses packages from the OS repository for one installation and compiled source for the second, there could be subtle (or not-so-subtle even) differences between the two installations that cause a problem to appear in one but not the other.
  • Thanks @kwilson & @ilikepi. I'll probably set up a separate server as you suggest in the future. In the meantime, I'm going to try mod_proxy or second IP.

    I just tried mod_proxy - added the snippet below to /etc/apache2/apache2.conf (production config) following:
    http://httpd.apache.org/docs/2.0/mod/mod_proxy.htm

    It didn't work.. what am I doing wrong? Also, it says that I may be able to do this with RewriteRule? How would I do that?
    ------------------------------------------------------------------------------------------------
    ProxyRequests Off

    Order deny,allow
    Allow from all

    ProxyPass http://beta.mydomain.com:80 http://localhost:8080
    ProxyPassReverse http://beta.mydomain.com:80 http://localhost:8080
    ------------------------------------------------------------------------------------------------

    I actually set up the second apache by basically copying the first. It wasn't to preserve the same structure in the second apache - it just seemed easier for the newbie that I am. I encountered issues on the way so I posted a question:

    http://forum.slicehost.com/comments.php?DiscussionID=4096

    I got it to work eventually. Since I copied, I assume that the two apache servers are identical...or is it? Could there be something I'm missing by not installing apache via "aptitude install" as in the article? Initially, what I really wanted to do was do the exact same install for the second apache, but specify the directory to which it gets installed. I couldn't find a way to set "prefix" with the "aptitude install", thus the copy method. Any suggestions here?

    Thanks very much!
  • Your proxy lines should look like this:

    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/

    These go in the VirtualHost configuration for beta.example.com on the main Apache server, the one that's running on port 80.
  • That makes much more sense now!
    I just appended the VirtualHost (shown below) to the already existing vhost config file for main apache - and everything works now.
    Thanks so much for your help!


    ServerName beta.mydomain.com

    ProxyRequests Off
    ProxyPreserveHost On

    Order deny,allow
    Allow from all

    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/