0

I have Node.js/Angularjs/Gulp application running on www.myurl.com:3001 and I would like to have a "clean" URL www.myurl.com. So I would like to redirect the traffic from www.myurl.com to www.myurl.com:3001, which is pretty straight foreward with a .htaccess mod rewrite condition. But what I get is now a redirect from www.myurl.com to www.myurl.com:3001 and I would like to see the application running on port 3001 under the URL without any additional port, so that any user that visits the URL www.myurl.com sees the application running on www.myurl.com:3001, but has a "clean" URL without any port number in his browser:www.myurl.com.

What would be the best way to do it? Here´s what I got so far:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.myurl.com [NC]
RewriteRule (.*) http://www.myurl.com:3001/$1 [R=301,L]

Any hints or help would be appreciated, thanks!

DWA
  • 530
  • 1
  • 5
  • 29
  • 1
    try to remove this `R=301` flag! – Abhishek Gurjar Aug 30 '16 at 12:18
  • @Abhishekgurjar - Thanks so far, but I still get www.myurl.com:3001 in the browser, when I enter www.myurl.com. I would like to make the port "disappear" or to hide the port. Any more hints, may be? – DWA Aug 30 '16 at 12:24

2 Answers2

1

You can't just redirect it, as that will always show the port.

You need to configure a reverse proxy in Apache. This can be done like in this StackOverflow answer and would look a little like this in your apache configuration:

<VirtualHost *:80>
    ServerAdmin admin@myurl.com
    ServerName myurl.com
    ServerAlias www.myurl.com

    ProxyRequests off

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    <Location />
        ProxyPass http://localhost:3001/
        ProxyPassReverse http://localhost:3001/
    </Location>
</VirtualHost>
Community
  • 1
  • 1
Allan Kimmer Jensen
  • 4,333
  • 2
  • 31
  • 53
  • thanks so far, but that didn´t solved my problem. I tried this Vhost directive a couple of times, but it always gives me an Internal server error when visiting www.myurl.com, and the application is still running on www.myurl.com:3001 – DWA Aug 30 '16 at 13:50
  • @DWA2112 So fix the internal server error (details will be in the logs). Of course the application is still running on 3001. Use your firewall to only allow internal traffic to it or something. – ceejayoz Aug 30 '16 at 14:31
1

Two methods

  1. change port number

    Listen 3001

http://httpd.apache.org/docs/2.2/mod/mpm_common.html#listen

  1. Reverse proxy

    <VirtualHost *:80> ProxyPreserveHost On ProxyRequests Off ServerName www.myurl.com ServerAlias myurl.com ProxyPass / http://myurl.com:3001/ ProxyPassReverse / http://myurl.com:3001/ </VirtualHost>

Abhishek Gurjar
  • 7,426
  • 10
  • 37
  • 45
  • thanks so far, but that didn´t solved my problem. I tried this Vhost directive a couple of times, but it always gives me an Internal server error when visiting www.myurl.com, and the application is still running on www.myurl.com:3001 – DWA Aug 30 '16 at 13:50