nginx,

Reference Nginx upstream config from another file

Apr 25, 2023 · 1 min read · Post a comment

The “include” directive is used to include another file into the current Nginx configuration file. This allows you to split your Nginx configuration across multiple files, making it easier to manage and organize. So, here’s how is done.

Prerequisites

  • Nginx

Solution

Given that you have the following upstream.conf file:

upstream backend {
    server bcknd1.devcoops.com;
    server bcknd2.devcoops.com;
}

To include in your Nginx configuration, add the following line:

include /etc/nginx/conf.d/upstreams.conf;

Now, reference it in your root location. For instance:

location / {
    proxy_pass http://bcknd;
}

Conclusion

In case nothing works, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.