Rewrite domain.com:3000 to port 80 with Apache

13,655
<VirtualHost *:80>
ServerName errbit.ourcompany.com
ProxyPreserveHost On
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost> 

http://httpd.apache.org/docs/2.0/mod/mod_proxy.html

Share:
13,655

Related videos on Youtube

Josef van Niekerk
Author by

Josef van Niekerk

With nearly 14 years of experience in software development and eCommerce, I am utterly infatuated with technology. I eat challenge for breakfast, and like to make technological problems disappear. I am a strong team player, take constructive criticism extremely well. I have a strong belief, that to become better, we have to be around people that are more experienced than oneself. My favorite time spent at work is building and coding cutting edge interactive UI's that makes any system fun and easy to use, and is where my ability to think creatively and logically comes in very handy. My main life ingredient includes learning, and therefore enjoy constantly enriching my skills by taking online courses, watching endless hours of videos, and tinkering with whatever I can get my hands on. I enjoy doing carpentry, home DIY and tinkering with an Arduino and some electronics.

Updated on September 18, 2022

Comments

  • Josef van Niekerk
    Josef van Niekerk over 1 year

    I'm hosting two applications on my web server, one is a Drupal site, and the other is an Errbit installation, which is a Ruby on Rails application. The URLs looks something like this:

    http://ourcompany.com
    http://errbit.ourcompany.com:3000
    

    I want to drop the need for :3000 on the second URL, so we can access it directly via:

    http://errbit.ourcompany.com
    

    I don't want to redirect, I want the URL to remain, without the port number. I've previously used the following command line commands to set some IP table reconfiguration:

    sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000 
    sudo iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 3000
    

    ...which worked fine, as there was no Apache running on the old server. However, this will cause ALL requests on port 80 to be redirected to port 3000, meaning it will break access to http://ourcompany.com

    How do I set this up?

    Is there a way to configure the IP tables to allow this, or would this be done in the Apache2 configuration?