change base url in airflow

The default base URL of airflow is http://localhost:8080 and because of this, you may get an issue that log files URL is still showing localhost and you have to remove localhost and replace it with your actual domain on which airflow is running.

The solution to this problem is to change the base URL of airflow in airflow.cfg file or you can change the base URL from an environment variable. We will discuss both the way in detail moving forward.

1. Change the base URL from airflow.cfg file:

Open the airflow.cfg file and find the base_url in webserver section and then change the value from http://localhost:8080 to http://your_ip_or_domain:port

2. Change the base URL from the environment variable:

Airflow also provides an option to set the airflow.cfg variables from environment variable and thing to keep in mind that variables set from environment variable have the higher precedence from airflow.cfg modification.

AIRFLOW__WEBSERVER__BASE_URL=http://your_ip_or_domain:port
export AIRFLOW__WEBSERVER__BASE_URL

You can use any of the above methods and restart the airflow, now airflow will use the new base URL in log file links etc instead of showing localhost:8080.

Let us know if this solution doesn’t fix the issue.

Happy Coding!!