proxy_fix.rst
This file
Path
docs/deploying/proxy_fix.rst
33 lines · 1.3 KiB
Last changed by
Merge pull request #4637 from pallets/docs-deployDavid Lordbefore adoptionb0a144d
History of this fileTake it
1Tell Flask it is Behind a Proxy2===============================34When using a reverse proxy, or many Python hosting platforms, the proxy5will intercept and forward all external requests to the local WSGI6server.78From the WSGI server and Flask application's perspectives, requests are9now coming from the HTTP server to the local address, rather than from10the remote address to the external server address.1112HTTP servers should set ``X-Forwarded-`` headers to pass on the real13values to the application. The application can then be told to trust and14use those values by wrapping it with the15:doc:`werkzeug:middleware/proxy_fix` middleware provided by Werkzeug.1617This middleware should only be used if the application is actually18behind a proxy, and should be configured with the number of proxies that19are chained in front of it. Not all proxies set all the headers. Since20incoming headers can be faked, you must set how many proxies are setting21each header so the middleware knows what to trust.2223.. code-block:: python2425 from werkzeug.middleware.proxy_fix import ProxyFix2627 app.wsgi_app = ProxyFix(28 app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=129 )3031Remember, only apply this middleware if you are behind a proxy, and set32the correct number of proxies that set each header. It can be a security33issue if you get this configuration wrong.