# Include additional files

**URL:** <https://www.ruby-forum.com/t/include-additional-files/228515>\
**Category:** NGINX\
**Created:** [April 25, 2013, 9:09am UTC](https://www.ruby-forum.com/t/include-additional-files/228515 "2013-04-25T09:09:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SSJSSrg\_KastningSS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@SSJSSrg\_KastningSS\_S](https://www.ruby-forum.com/u/SSJSSrg_KastningSS_S)\
**Post date:** [April 25, 2013, 9:09am UTC](https://www.ruby-forum.com/t/include-additional-files/228515/1 "2013-04-25T09:09:26Z")

</div>

Hi.

I have some trouble cleaning up my /etc/nginx/nginx.conf. I have several  
upstream and server blocks in this file and it becomes a mess. So I  
tried  
to write each configuration in a seperate file saved in  
/etc/nginx/conf.d/loki.conf for example and include them in nginx.conf.

I include the file with the following entry in nginx.conf:  
include /etc/nginx/conf.d/loki.conf;

But when reloading/restarting nginx I get the following error:  
[emerg] 15941#0: duplicate upstream “loadbalancer” in  
/etc/nginx/conf.d/loki.conf:1

I looked around in the Wiki but find no hint.

How can I store my configruations in seperate files and include them?

Greetz

Joerg

---

<div class="post-metadata">

**Author:** ![SSJSSrg\_KastningSS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@SSJSSrg\_KastningSS\_S](https://www.ruby-forum.com/u/SSJSSrg_KastningSS_S)\
**Post date:** [April 26, 2013, 7:47am UTC](https://www.ruby-forum.com/t/include-additional-files/228515/2 "2013-04-26T07:47:59Z")

</div>

Ok. So the upstream block has to be in the nginx.conf. I thought I could  
this one export to a separate file, too.

I was wondering why I still got the error message after I deleted the  
upstream block in nginx.conf and had it only in my included file. So the  
upstream configuration must be in nginx.conf?

2013/4/25 motto [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![SSJSSrg\_KastningSS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@SSJSSrg\_KastningSS\_S](https://www.ruby-forum.com/u/SSJSSrg_KastningSS_S)\
**Post date:** [April 25, 2013, 9:16am UTC](https://www.ruby-forum.com/t/include-additional-files/228515/3 "2013-04-25T09:16:27Z")

</div>

upstream name should be unique per entire config, you could name it in  
nginx.conf and than reference to its name from different your includes.  
like:  
upstream loadbalancer {  
server 192.168.0.1:8080;  
server 192.168.0.2:8080;  
server 192.168.0.3:8080;  
server 192.168.0.4:8080;  
}

than in certain location (in included file for example)  
proxy\_pass [http://loadbalancer](http://loadbalancer);

Posted at Nginx Forum:

> **[Re: Include additional files](https://forum.nginx.org/read.php?2,238628,238629#msg-238629)**
>
> Hi. I have some trouble cleaning up my /etc/nginx/nginx.conf. I have several upstream and server blocks in this file and it becomes a mess. So I tried to write each configuration in a seperate file saved in /etc/nginx/conf.d/loki.conf for example and...

---

<div class="post-metadata">

**Author:** ![SSJSSrg\_KastningSS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@SSJSSrg\_KastningSS\_S](https://www.ruby-forum.com/u/SSJSSrg_KastningSS_S)\
**Post date:** [April 26, 2013, 8:05am UTC](https://www.ruby-forum.com/t/include-additional-files/228515/4 "2013-04-26T08:05:31Z")

</div>

> Ok. So the upstream block has to be in the nginx.conf. I thought I  
> could  
> this one export to a separate file, too.

yes, you can (include your upstream-config and any other part).  
you just need to place it into the right context, e.g. inside  
a http { … } - block and not inside a server { … } - block

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

> I was wondering why I still got the error message after I deleted the  
> upstream block in nginx.conf and had it only in my included file. So  
> the  
> upstream configuration must be in nginx.conf?

every upstream-config for each of your server-parts gets a **unique**  
name,

what does $ grep -Rn “loadbalancer” /etc/nginx/\*  
gives you back? might be just a typo.

> 

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,238628,238655#msg-238655](http://forum.nginx.org/read.php?2,238628,238655#msg-238655)
