How to rewrite dynamic URL?

Rewrite rule to hide port from URL of Rails server?

  • I have a rails server running on URL "http://example.com:1234" I want to  provide the URL of this application to an user as  "http://example.com/myapp" so that Apache (or Rack or whatever you  suggest that works) can redirect request for "/myapp" to port 3333 of  that domain.

  • Answer:

    The easiest option is to set the rails server port to 80. You can edit the configs to listen on port 80. This is the easiest set up and most memory economical. However, I see that you wan to set up the app at <domain>/myapp . Perhaps there is another process listening on port 80 running on the same server. In this case, you need to configure that process(it can be apache webrick or tomcat or anything) to redirect /myapp to rails servers. If you already have Apache, or in case you can install apache for handling port 80. Do the following things : Enable the proxy and proxy_http mods of apache using sudo a2enmod proxy sudo a2enmod proxy_http Include two directives in your httpd.conf file for each web application that you wish to forward to Rails. For example, to forward an application at context path /myapp: ProxyPass /myapp http://localhost:3000 ProxyPassReverse /myapp http://localhost:3000 which tells Apache to forward URLs of the form port 80 to the rails server listening on port 8081. You need to restart apache with sudo service apache2 restart You may then wish to prevent external connections to rails server by binding rails server only to 127.0.0.1 .

Vibhav Sinha at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.