1

Little description: Redirect port 5000 to a subdomain

Description: Well I have a program, "supervisor" It has a OSRM (open street routing map), It is running in port 5000, I want to redirect that port to a subdomain example.mywebsite.com, all with Apache

My SO: is Ubuntu 14.04.4 LTS

Apache version: Apache/2.4.7 (Ubuntu)

I have a file for every subdomain in : /etc/apache2/sites-available/

I want a file for my problem there...

I don't know how to do It. This will help another, and I'm doing a tuto of installing nominatim, and osrm, with apache...

1 Answers1

4

Well you have the service running in port 5000, you want to show,proxy you service that is in 127.0.0.1:5000 or in mywebsite.com:5000 to a subdomain or domain like osrm.mywebsite.com or myosrmwebsite.com

You'll need to enable mod_proxy in Apache2 first. So run these commands as root, or sudo:

a2enmod proxy
a2enmod proxy_http

Edit your hosts file

# if you don't have access try with sudo
nano /etc/hosts

Add entry to your hosts file

# path /etc/hosts
127.0.0.1 subdomainname.mywebsite.com
87.164.25.1 subdomainname.mywebsite.com

The 87.164.25.1 is an example of ip public it isn't real

After this we need to go to /etc/apache2/sites-available

cd /etc/apache2/sites-available

Create a file *.conf for our subdomain or domain

nano subdomainname.mywebsite.com.conf

In this file we are going to create a config to proxy our port to servername

#filename 'subdomainname.mywebsite.com.conf'
#dir /etc/apache2/sites-available
<VirtualHost *:80>
    ServerName osrm.website.com  # my subdomain or website name server
    ProxyPass               /       http://localhost:5000/
    ProxyPassReverse        /       http://localhost:5000/
    ProxyRequests     Off

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

note: If when you try to see the website through the url, and nothing happened, try change <VirtualHost *:80> to <VirtualHost 87.164.25.1:80> the ip that server has.

Add the *.conf file to apache with this command, and check the list of commands.

To enable it

sudo a2ensite subdomainname.mywebsite.com.conf

To disable it

sudo a2dissite subdomainname.mywebsite.com.conf

To list all sites enables

# if you want to know what sites are enables.. or check if it is enable
apache2ctl -S

To reload apache or restart

# only reload the config files without restart
sudo service apache2 reload

# restart apache
sudo service apache2 restart


Websites of reference

  1. How to setup subdomain on Ubuntu Server 14.04
  2. Get a list of all virtual hosts which are defined in all apache configuration files
  3. Proxy port to site - example No. 1 - https://serverfault.com/a/140161
  4. Proxy port to site - example No. 2 - http://freedif.org/how-to-redirect-a-port-to-a-sub-domain-proxypass/
  5. Proxy port to site - example No. 3 - https://stackoverflow.com/a/8442270/5287072
  6. Proxy port to site - example No. 4 - https://stackoverflow.com/a/589479/5287072

* I put a title and url if for some reason it fail...