# Question regarding Nginx Configuration

**URL:** <https://www.ruby-forum.com/t/question-regarding-nginx-configuration/212363>\
**Category:** NGINX\
**Created:** [September 30, 2011, 8:37pm UTC](https://www.ruby-forum.com/t/question-regarding-nginx-configuration/212363 "2011-09-30T20:37:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [September 30, 2011, 8:37pm UTC](https://www.ruby-forum.com/t/question-regarding-nginx-configuration/212363/1 "2011-09-30T20:37:22Z")

</div>

I have Nginx up and running but I think that the conf file could be  
improved upon.

I have a single server hosting 2 domains (doma and domb).

doma is the default virtual host and supports a number of applications  
all of which use Perl scripts.

domb has a separate domain name (obviously!) and supports one  
application that has a Wordpress/PHP frontend plus a secure Perl  
application

All doma static web pages are held in sub-directories under a root of  
…/htdocs

The domb ‘static’ Wordpress pages (including all PHP pages) are in  
…/htdocs/domb & sub-directories

All Perl scripts for both doma and domb are in …/cgi-bin  
sub-directories including …/cgi-bin/domb for the secure domb apps.

As I understand it I have to have 3 server blocks:-

Block 1 - default port 80  
Block 2 - domb port 80  
Block 3 - domb port 443

Unfortunately it seems that I have to replicate the location …htdocs  
and cgi-bin\*.pl$ blocks3 times (once for each server block) and the  
/\*.php$ block twice (for domb 80 and domb 443). This, I think, is  
because location blocks can only exist within server blocks.

Is it possible for location blocks to exist within the main http block  
at a higher level than the server block (I’ve tried it and it didn’t  
work for me but that might have been because I had got some other  
configuration statements wrong)?

TIA

Doug

Posted at Nginx Forum:

> **[Question regarding Nginx Configuration](https://forum.nginx.org/read.php?2,216128,216128#msg-216128)**
>
> I have Nginx up and running but I think that the conf file could be improved upon. I have a single server hosting 2 domains (doma and domb). doma is the default virtual host and supports a number of applications all of which use Perl scripts. domb...

---

<div class="post-metadata">

**Author:** ![dougconran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dougconran](https://www.ruby-forum.com/u/dougconran)\
**Post date:** [October 1, 2011, 3:50am UTC](https://www.ruby-forum.com/t/question-regarding-nginx-configuration/212363/2 "2011-10-01T03:50:14Z")

</div>

> Is it possible for location blocks to exist within the main http block at  
> a higher level than the server block?

No, but if you have a lots of repeating configuration/locations in the  
server blocks you can move those to a seperate file and then use include  
(  
[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/CoreModule#include) ) instead.

rr

---

<div class="post-metadata">

**Author:** ![dougconran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dougconran](https://www.ruby-forum.com/u/dougconran)\
**Post date:** [October 1, 2011, 2:07pm UTC](https://www.ruby-forum.com/t/question-regarding-nginx-configuration/212363/3 "2011-10-01T14:07:39Z")

</div>

Yes, I thought of that and it would certainly reduce the amount of  
duplication. However I do think that there are times when location  
directives apply to the whole server (the real server, that is, not the  
virtual host) and it would be nice to be able to use them at the higher  
level.

Maybe that is one for the wishlist?

Doug

Posted at Nginx Forum:

> **[Re: Question regarding Nginx Configuration](https://forum.nginx.org/read.php?2,216128,216154#msg-216154)**
>
> I have Nginx up and running but I think that the conf file could be improved upon. I have a single server hosting 2 domains (doma and domb). doma is the default virtual host and supports a number of applications all of which use Perl scripts. domb...

---

<div class="post-metadata">

**Author:** ![dougconran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dougconran](https://www.ruby-forum.com/u/dougconran)\
**Post date:** [October 3, 2011, 3:13pm UTC](https://www.ruby-forum.com/t/question-regarding-nginx-configuration/212363/4 "2011-10-03T15:13:09Z")

</div>

## Igor S. Wrote:

> Igor S.

I guess that is certainly enough reason not to include them in Nginx -  
and thank you for making a very good alternative available, I certainly  
couldn’t do any better!

My question, originally, was about whether I had correctly understood  
how to construct the conf file; or whether it could be done more  
efficiently and I had not understood how to do that.

However, my config works and it was a lot easier than Apache - maybe I  
should just count my blessings.

Doug

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

---

<div class="post-metadata">

**Author:** ![dougconran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dougconran](https://www.ruby-forum.com/u/dougconran)\
**Post date:** [October 2, 2011, 3:15pm UTC](https://www.ruby-forum.com/t/question-regarding-nginx-configuration/212363/5 "2011-10-02T15:15:56Z")

</div>

On Sat, Oct 01, 2011 at 08:07:03AM -0400, dougconran wrote:

> Yes, I thought of that and it would certainly reduce the amount of  
> duplication. However I do think that there are times when location  
> directives apply to the whole server (the real server, that is, not the  
> virtual host) and it would be nice to be able to use them at the higher  
> level.
> 
> Maybe that is one for the wishlist?

Locations, Directories, and other blocks in the global server  
configuration is one of features I never liked in Apache, so  
this is reason why they were not implemented in nginx.

–  
Igor S.
