Search code examples
apacheubuntunginxwebsocketratchet

Configure NGINX Reverse Proxy in front of Apache Web Server


So I started using Ratchet (library to program and use a websocket server in PHP, http://socketo.me/docs/hello-world) to program a chat application on my website (on the web server itself).

I set it all up on my localhost and it all works. Now I wanna deploy it on my web server, which is an Apache Server. For this to work, I apparently need to configure a reverse proxy, ideally with NGINX, in front of my web server, because the websocket server cannot simply listen on the same port as my Apache server.

When searching for sources which explain how to configure a reverse proxy with NGINX in front of my Apache web server, search results / articles / tutorials always tell me how to configure a reverse proxy using NGINX on an Apache WebServer ON UBUNTU. I'm confused why Ubuntu always comes into play here; isn't it simply possible to configure an NGINX reverse proxy in front of my Apache web server, without the use of Ubuntu?

UPDATE

My server is a web server on a shared hosting basis, and I have no root access. So is it actually even possible to place a reverse proxy in front of my web server, given that I can't even change to which port my web server listens..?

To may describe in a better way what EXACTLY I want: A specific page of my website should load its content (html structure, representing a chat window) from the web server, but its chat functionality, present as PHP Ratchet script on the server-side, should work via a WebSocket connection. In other words, for this page, Web Server and WebSocket connections should work simultaneously, while I have only one Apache server, on a shared hosting basis, with no root access, on which both the chat application programmed in Ratchet and the website's HTML page are present (at least on my localhost, this worked very nicely). Is that even possible to deploy given my hosting conditions, or do I need to switch to another hosting type?

Also, please don't consider this question to be specific to nginx. According to the documentation in Ratchet, the solutions I have are:

  1. Run web site and WebSocket server on the same machine using port 8080 for WebSockets and take the chance client proxies won't block traffic

  2. Run WebSocket server on its own server on port 80 under a subdomain (sock.example.com)

  3. Put a reverse proxy (Nginx, HAProxy, Varnish) in front of your web server and WebSocket server

I also figured out (github)

  1. Use the mod_proxy_wstunnels extension available for Apache

I'm more than happy to know about any of the four or other recommended solution, even if this wouldn't include nginx.


Solution

  • Following the UPDATE section: We'll assume that you can't place a reverse proxy in front of your hosted solution within the hosting solution itself. That seems very unlikely.

    My best bet would be to setup a reverse proxy on a dedicated VPS and pass all your trafic through this but this setup is far more convoluted than you probably require.


    From the line "[...] on my web server, which is an Apache Server." I guess you are using a mutualized hosting solution. In which case, it'll depend heavily on which specific host you are using. In your CPannel try to look for "reverse proxy"/"proxy"/"socket"/"web socket" parameters.

    If you're hosting on VPS and your distribution of linux of the "family" as ubuntu, follow a tutorial and it might just work. Otherwise, look for a tutorial specific to your distribution (or OS if you're not on linux).