# How can I use environment variables in Nginx.conf

You can use environment variables in your Nginx configuration (nginx.conf) by making use of the `env` module and the `set` directive. Here's how you can do it:

### Step 1 -**Install the `nginx` with `env` module**

First, make sure you have Nginx installed with the `ngx_http_env_module` module. You can check if your Nginx installation includes this module by running:

```bash
nginx -V 2>&1 | grep ngx_http_env_module
```

If you don't see any output, you might need to recompile Nginx with the module enabled or install a version of Nginx that includes it.

### Step 2 - **Set Environment Variables**

Define the environment variables you want to use in your Nginx configuration. You can do this in various ways, depending on your server environment. For example, you can set them in your system environment or use a tool like systemd's `Environment` directive for systemd service units.

### Step 3 - **Modify Your Nginx Configuration**

Open your `nginx.conf` file and use the `set` directive to assign values to variables using the `env` module. Here's an example of how you can use an environment variable:

```
http {
    server {
        location / {
            set $my_variable $MY_ENV_VARIABLE;
            # Now, you can use $my_variable in your configuration.
            # For example, in a proxy_pass directive:
            proxy_pass http://$my_variable;
        }
    }
}
```

In this example, the environment variable `MY_ENV_VARIABLE` is assigned to the Nginx variable `$my_variable`.

### Step 4 - **Reload or Restart Nginx**

After modifying your Nginx configuration, you need to reload or restart Nginx for the changes to take effect.

```bash
sudo systemctl reload nginx
```

Now, Nginx will use the value of the environment variable `MY_ENV_VARIABLE` in your configuration.

Make sure the environment variable is set and accessible to the user running the Nginx process. The exact method for setting environment variables may vary depending on your operating system and deployment environment.