Running Airflow behind a reverse proxy

Airflow can be set up behind a reverse proxy, with the ability to set its endpoint with great flexibility.

For example, you can configure your reverse proxy to get:

  1. https://lab.mycompany.com/myorg/airflow/

To do so, you need to set the following setting in your airflow.cfg:

  1. base_url = http://my_host/myorg/airflow

Additionally if you use Celery Executor, and you enable flower, you can get Flower in /myorg/flower with:

  1. flower_url_prefix = /myorg/flower

Your reverse proxy (ex: nginx) should be configured as follow:

  • pass the url and http header as it for the Airflow webserver, without any rewrite, for example:

    1. server {
    2. listen 80;
    3. server_name lab.mycompany.com;
    4. location /myorg/airflow/ {
    5. proxy_pass http://localhost:8080;
    6. proxy_set_header Host $http_host;
    7. proxy_redirect off;
    8. proxy_http_version 1.1;
    9. proxy_set_header Upgrade $http_upgrade;
    10. proxy_set_header Connection "upgrade";
    11. }
    12. }
  • rewrite the url for the flower endpoint:

    1. server {
    2. listen 80;
    3. server_name lab.mycompany.com;
    4. location /myorg/flower/ {
    5. rewrite ^/myorg/flower/(.*)$ /$1 break; # remove prefix from http header
    6. proxy_pass http://localhost:5555;
    7. proxy_set_header Host $http_host;
    8. proxy_redirect off;
    9. proxy_http_version 1.1;
    10. proxy_set_header Upgrade $http_upgrade;
    11. proxy_set_header Connection "upgrade";
    12. }
    13. }

To ensure that Airflow generates URLs with the correct scheme when running behind a TLS-terminating proxy, you should configure the proxy to set the X-Forwarded-Proto header, and enable the ProxyFix middleware in your airflow.cfg:

  1. [webserver]
  2. enable_proxy_fix = True

If you need to configure the individual parameters to the ProxyFix middleware, you can set them individually in your airflow.cfg:

  1. [webserver]
  2. proxy_fix_x_for = 1
  3. proxy_fix_x_host = 3

Note

You should only enable the ProxyFix middleware when running Airflow behind a trusted proxy (AWS ELB, nginx, etc.).