title: Proxy dash on twisted using nginx results in "Error loading layout"
body: <p>I implemented a dash dashboard for running in a productive scenario with twisted by (relevant code of <strong>my_dashboard.py</strong>)</p>
  
  <pre><code>import dash
  import flask
  from twisted.internet import reactor
  from twisted.web.server import Site
  from twisted.web.wsgi import WSGIResource
  import werkzeug.serving
  
  server = flask.Flask(__name__)
  app = dash.Dash(__name__, server=server)
  app.layout = html.Div(html.P('My dashboard content'))
  
  def run_twisted_wsgi():
      reactor_args = {'installSignalHandlers': False}
      resource = WSGIResource(reactor, reactor.getThreadPool(), server.wsgi_app)
      site = Site(resource)
      reactor.listenTCP(8050, site)
      reactor.run(**reactor_args)
  
  if __name__ == '__main__':
      run_twisted_wsgi = werkzeug.serving.run_with_reloader(run_twisted_wsgi)
      run_twisted_wsgi()
  </code></pre>
  
  <p>Which runs as expected at port 8050. Now I want to proxy the application using nginx to <a href="http://my.server/dash/my_dashboard" rel="nofollow noreferrer">http://my.server/dash/my_dashboard</a>. I use the following configuration in <strong>/etc/nginx/sites-available/my.server.net</strong> (which is as well linked to /etc/nginx/sites-enabled/my.server.net)</p>
  
  <pre><code>server {
    listen 80;
    server_name my.server.net;
  
    location /dash/my_dashboard {
      proxy_pass  http://0.0.0.0:8050;
      proxy_redirect off;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
    }
  }
  </code></pre>
  
  <p>While this does not affect accessing the dashboard by <code>http://my.server.net:8050</code> accessing it by the desired `<a href="http://my.server.net/dash/my_dashboard" rel="nofollow noreferrer">http://my.server.net/dash/my_dashboard</a> gives me a "Error loading layout" instead of the dashboard. </p>
  
  <p>Perhaps it is something with the nginx config wrong or the dash configuration needs special treatment. Can anyone give some advice her?</p>
  
  <p>I tried already the suggested proxyfixes applied on <code>server.wsgi_app</code></p>
  
  <pre><code>from werkzeug.contrib.fixers import ProxyFix
  </code></pre>
  
  <p>and another suggestion</p>
  
  <pre><code>class CustomProxyFix(object):
      def __init__(self, app):
          self.app = app
  
      def __call__(self, environ, start_response):
          host = environ.get('HTTP_X_FHOST', '')
          if host:
              environ['HTTP_HOST'] = host
          return self.app(environ, start_response)
  </code></pre>
  
  <p>which both have not been able to solve the problem. Perhaps also a change to the dash config might do it, so far I have tried to vary these settings</p>
  
  <pre><code>app.config.update({
      'routes_pathname_prefix': '/',
      'requests_pathname_prefix': '/',
      })
  </code></pre>
  
  <p>without success.</p>