title: How can I use XDebug with a PHP upstream behind an nginx reverse proxy?
body: <p>I have a PHP server running through PHP-FPM which is served with fastcgi through nginx on port <code>7000</code>. This application has been dockerized and is running as a running container, e.g. <strong>my_api</strong>.</p>
  
  <p>The <code>my_api</code> docker container can be connected to directly via port <code>7000</code> (for sanity checking) as well as through another container which acts as an nginx reverse proxy that uses upstreams to expose the <code>my_api</code> application (and others) on ports <code>80</code> and <code>443</code> (port <code>80</code> redirects to SSL) through <code>proxy_pass</code> directives under the appropriate locations.</p>
  
  <p>If I start an XDebug session using <strong>dbgp</strong> on port <code>9000</code> directly against a file served from <a href="http://localhost:7000">http://localhost:7000</a> I can see the debugging session established correctly and I can debug.</p>
  
  <p>However, if I attempt to start the XDebug session against the URL served by the nginx reverse proxy, e.g. <a href="https://localhost/my-api">https://localhost/my-api</a>, the debug session does not appear to start or at least it doesn't create the connection properly (no breakpoints are hit in my IDE, etc.).</p>
  
  <p>How can I establish an XDebug session for requests made through the nginx reverse proxy?</p>
  
  <p>For purposes of this question, below is a (relevant) sample of my <code>docker-compose.yml</code> configuration and <code>xdebug.ini</code>:</p>
  
  <p><strong>docker-compose.yml</strong>:</p>
  
  <pre><code>version: "2"
  
  services:
    api:
      build: &lt;path_to_dockerfile&gt;
      ports:
         - 7000:7000
         #- 9000:9000   # may be uncommented for direct debugging access
    nginx_proxy:
      build: &lt;path_to_dockerfile&gt;
      links:
        ...
        - api:api
      ports:
        - 80:80
        - 443:443
  </code></pre>
  
  <p><strong>xdebug.ini</strong></p>
  
  <pre><code>zend_extension=xdebug.so
  xdebug.remote_enable=true
  xdebug.remote_connect_back=1
  xdebug.remote_port=9000
  xdebug.remote_handler=dbgp
  xdebug.remote_autostart=0
  </code></pre>
  
  <hr>
  
  <p><strong>NB:</strong> I've tried a couple of different configurations to try and get this working, including launching a Docker container running a <a href="https://github.com/agroszer/komodo-python-dbgp">dbgpproxy</a> but nothing seems to allow me to debug requests which pass through the reverse proxy. It is very possible though that the configuration I was using for these attempts was just wrong.</p>
  
  <p>I have a few theories on what my problems may be, among them the suspicion that it is the reverse proxy's IP address that is being communicated to XDebug via the <code>remote_connect_back</code> configuration property.</p>
  
  <p>Any help or insight into how to properly configure XDebug to work with requests that are made to a server via nginx proxy passes to an upstream server would be greatly appreciated!</p>
  
  <p>I can provide further details if it would be helpful!</p>