title: How to configure Traefik to be in front of Nginx and a PHP-FPM WebSocket server?
body: <p>I'd like to use <a href="https://github.com/traefik/traefik" rel="nofollow noreferrer">Traefik</a> as a reverse proxy behind a Ratchet WebSocket server (3rd option suggested in <a href="http://socketo.me/docs/deploy#server_configuration" rel="nofollow noreferrer">deploy section</a>).</p>
  <p>The goal is to manage HTTPS and wss with the reverse proxy while keeping a simple HTTP and ws on the Ratchet server.</p>
  <p>My WebSocket server exposes on port 8080, like in <a href="http://socketo.me/docs/push#tying_it_together" rel="nofollow noreferrer">this example</a>:</p>
  <pre class="lang-php prettyprint-override"><code>public function run()
  {
      $loop   = React\EventLoop\Factory::create();
      $pusher = new Pusher();
  
      // Listen for the web server to make a ZeroMQ push after an AJAX request
      $context = new React\ZMQ\Context($loop);
      $pull    = $context-&gt;getSocket(ZMQ::SOCKET_PULL);
      $pull-&gt;bind('tcp://0.0.0.0:5555');
      $pull-&gt;on('message', array($pusher, 'onEntry'));
  
      // Set up our WebSocket server for clients wanting real-time updates 
      $webSock = new React\Socket\Server('0.0.0.0:8443', $loop); 
  
      $webServer = new IoServer(
          new HttpServer(
              new WsServer(
                  new WampServer(
                      $pusher
                  )
              )
          ),
          $webSock
      );
  
      $loop-&gt;run();
  }
  </code></pre>
  <p>Following <a href="https://github.com/wodby/docker4drupal/issues/407#issuecomment-596023256" rel="nofollow noreferrer">this post</a>, I have been able to configure HTTPS via Traefik.</p>
  <p>Here is my simplified <em>docker-compose.yml</em>:</p>
  <pre class="lang-yaml prettyprint-override"><code>nginx:
    image: wodby/nginx:$NGINX_TAG
    container_name: &quot;${PROJECT_NAME}_nginx&quot;
    depends_on:
      - php
    environment:
      NGINX_STATIC_OPEN_FILE_CACHE: &quot;off&quot;
      NGINX_ERROR_LOG_LEVEL: debug
      NGINX_BACKEND_HOST: php
      NGINX_SERVER_ROOT: /var/www/html/webroot
      NGINX_VHOST_PRESET: $NGINX_VHOST_PRESET
    volumes:
      - ./html:/var/www/html:cached
    labels:
      - &quot;traefik.http.routers.${PROJECT_NAME}_nginx.rule=Host(`${PROJECT_BASE_URL}`)&quot;
      - &quot;traefik.http.middlewares.${PROJECT_NAME}_nginx_https.redirectscheme.scheme=https&quot;
      - &quot;traefik.http.routers.${PROJECT_NAME}_nginx.entrypoints=web&quot;
      - &quot;traefik.http.routers.${PROJECT_NAME}_nginx.middlewares=${PROJECT_NAME}_nginx_https@docker&quot;
      - &quot;traefik.http.routers.${PROJECT_NAME}_nginx_https.rule=Host(`${PROJECT_BASE_URL}`)&quot;
      - &quot;traefik.http.routers.${PROJECT_NAME}_nginx_https.tls=true&quot;
      - &quot;traefik.http.routers.${PROJECT_NAME}_nginx_https.entrypoints=websecure&quot;
  
  php:
    build:
      context: .
      dockerfile: docker/php-fpm/Dockerfile
    container_name: &quot;${PROJECT_NAME}_php&quot;
    volumes:
      - ./html:/var/www/html
    labels:
      - &quot;traefik.http.routers.php.rule=Host(`${PROJECT_BASE_URL}`)&quot;
  
  traefik:
    image: traefik:v2.0
    container_name: &quot;${PROJECT_NAME}_traefik&quot;
    command:
      - &quot;--api.insecure=true&quot;
      - &quot;--entrypoints.web.address=:80&quot;
      - &quot;--entrypoints.websecure.address=:443&quot;
      - &quot;--providers.docker=true&quot;
      - &quot;--providers.file.filename=/etc/traefik/dynamic_conf/config.yml&quot;
      - &quot;--providers.file.watch=true&quot;
    ports:
      - &quot;80:80&quot;
      - &quot;443:443&quot;
    volumes:
      - &quot;/var/run/docker.sock:/var/run/docker.sock&quot;
      - &quot;./docker/traefik/config.yml:/etc/traefik/dynamic_conf/config.yml&quot; # used to define the certificate path
      - &quot;./docker/certs:/tools/certs&quot;
  </code></pre>
  <p>However, how can I now forward HTTPS/wss to HTTP/ws to the <em>php</em> service?</p>