icouto

Q: OSX Server Apache: How to Re-route http Request?

Hi all,

 

I have a Mac Mini running OSX Server El Capitan. It serves a couple of websites already. Normal server websites:

 

- site1.example.com

- site2.example.com

 

I have now installed an app that has its own web server built-in. That app would normally be accessible via http, on port 80. However, any http connections on port 80 are automatically trapped by OSX Server's built-in apache. Therefore, I have currently set the web app to run in a different port to apache. I have also setup a sub-domain, so that users can access that app directly, but they also have to type in the port as part of the URL - for instance, the new web app site is reachable at:

 

- myapp.example.com:7117

 

What I would like to do, is for the users to be able to simply access the app by using:

 

- myapp.example.com

 

I know that there is a way for us to get apache to automatically 'reroute' all requests for a sub-domain to an internal port, but I don't even know where to start. What files do we need to configure on OSX Server? How do we configure them?

 

Any guidance would be greatly appreciated.

Posted on Apr 23, 2016 10:53 PM

Close

Q: OSX Server Apache: How to Re-route http Request?

  • All replies
  • Helpful answers

  • by John Lockwood,Solvedanswer

    John Lockwood John Lockwood Apr 25, 2016 6:10 PM in response to icouto
    Level 6 (9,230 points)
    Servers Enterprise
    Apr 25, 2016 6:10 PM in response to icouto

    I had the same requirement and solved it the way you desire as detailed below.

     

    1. Set the additional app to run on a different port
    2. Create a site in Server.app using port 80 and the same host name as you intend to use for the additional app
    3. Define a redirect rule for this site in Server.app as follows
    4. Source = /, Destination = http://hostname.domain.com:1234/, Status = Permanent (301)

     

    Obviously use the correct hostname, domain and port for your situation.

     

    PS. The same approach as I detailed above can also be used to redirect port 80 to the matching https i.e. 443 site.

  • by icouto,

    icouto icouto Apr 25, 2016 6:14 PM in response to John Lockwood
    Level 1 (4 points)
    Servers Enterprise
    Apr 25, 2016 6:14 PM in response to John Lockwood

    Thank you for the help, @John!

     

    That will redirect the user to the URL with the port number attached, that is: the URL in the user's browser will change to reflect the port number used. This will be OK - and will already be useful - for some apps, but it won't for others. There are apps where it would be best, if possible, to have it all happen 'transparently' - that is, without the user even knowing that the requests are being redirected (without change in the browser's URL). Is that possible?

  • by pterobyte,Helpful

    pterobyte pterobyte Apr 26, 2016 9:35 PM in response to icouto
    Level 6 (11,101 points)
    Servers Enterprise
    Apr 26, 2016 9:35 PM in response to icouto

    You could set up a reverse proxy, but that means diving in deep under the hood and modifying configuration files.

    Here is an example for doing it with Kerio or Filemaker, but the same logic applies for any app running on a different port:

    http://www.precursor.ca/rais/

    (Scroll down to tutorials).