# VirtualDocumentRoot with 1.4.2

**URL:** <https://www.ruby-forum.com/t/virtualdocumentroot-with-1-4-2/236330>\
**Category:** NGINX\
**Created:** [August 27, 2013, 10:45am UTC](https://www.ruby-forum.com/t/virtualdocumentroot-with-1-4-2/236330 "2013-08-27T10:45:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [August 27, 2013, 10:45am UTC](https://www.ruby-forum.com/t/virtualdocumentroot-with-1-4-2/236330/1 "2013-08-27T10:45:32Z")

</div>

Hi there,

I’ve tried to replicate my Apache VirtualDocumentRoot /srv/www/%0 to  
nginx.

I have [Nginx 1.4 Virtual hosting](http://dabase.com/e/04055/) with

server\_name ~^(?.\*)$;  
root /srv/www/$vhost;  
access\_log /var/log/nginx/$vhost.access.log;

However it’s still logging to /var/log/nginx/access.log instead of  
/var/log/nginx/$vhost.access.log.

[root@sg ~]# cd /var/log/nginx/  
[root@sg nginx]# inotifywait -r -m .  
Setting up watches. Beware: since -r was given, this may take a  
while!  
Watches established.  
./ MODIFY access.log  
./ MODIFY access.log

`root /srv/www/$vhost;` works, but not `access_log /var/log/nginx/$vhost.access.log;`.

What am I missing?

Could my configuration upon [Nginx 1.4 Virtual hosting](http://dabase.com/e/04055/) be otherwise  
improved, without breaking it into individual server blocks?

Many thanks,

---

<div class="post-metadata">

**Author:** ![Kai\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e95f7d/32.png) [@Kai\_H](https://www.ruby-forum.com/u/Kai_H)\
**Post date:** [August 27, 2013, 1:33pm UTC](https://www.ruby-forum.com/t/virtualdocumentroot-with-1-4-2/236330/2 "2013-08-27T13:33:11Z")

</div>

Hello!

On Tue, Aug 27, 2013 at 04:43:12PM +0800, Kai H. wrote:

> `root /srv/www/$vhost;` works, but not `access_log /var/log/nginx/$vhost.access.log;`.
> 
> What am I missing?

> **[Module ngx\_http\_log\_module](http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log)**
>
> The ngx\_http\_log\_module module writes request logs in the specified format.

: The file path can contain variables (0.7.6+), but such logs have some  
: constraints:  
:  
: - the user whose credentials are used by worker processes should have  
: permissions to create files in a directory with such logs;  
:  
: - buffered writes do not work;  
:  
: - the file is opened and closed for each log write. However, since the  
: descriptors of frequently used files can be stored in a cache, writing  
to the  
: old file can continue during the time specified by the  
open\_log\_file\_cache  
: directive’s valid parameter  
:  
: - during each log write the existence of the request’s root directory  
is  
: checked, and if it does not exist the log is not created. It is thus a  
good  
: idea to specify both root and access\_log on the same level:

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![Kai\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e95f7d/32.png) [@Kai\_H](https://www.ruby-forum.com/u/Kai_H)\
**Post date:** [August 27, 2013, 2:29pm UTC](https://www.ruby-forum.com/t/virtualdocumentroot-with-1-4-2/236330/3 "2013-08-27T14:29:18Z")

</div>

On Tue, Aug 27, 2013 at 08:24:12PM +0800, Kai H. wrote:

> On Tue, Aug 27, 2013 at 03:32:29PM +0400, Maxim D. wrote:

Hi there,

> > : - the user whose credentials are used by worker processes should have  
> > : permissions to create files in a directory with such logs;
> 
> /var/log/nginx has +x on http user, so that’s fine.

+x doesn’t allow you to create files in a directory.

+w allows you to create files in a directory.

> I don’t understand how I fix my problem.

Does the error log give any indication of the problem?

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Kai\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e95f7d/32.png) [@Kai\_H](https://www.ruby-forum.com/u/Kai_H)\
**Post date:** [August 27, 2013, 4:56pm UTC](https://www.ruby-forum.com/t/virtualdocumentroot-with-1-4-2/236330/4 "2013-08-27T16:56:03Z")

</div>

On Tue, Aug 27, 2013 at 01:28:42PM +0100, Francis D. wrote:

> +w allows you to create files in a directory.

Sorry I meant to say +w

I think I must have got confused with one of my server blocks and not  
the wildcard. Sorry to trouble you. it seems to be to working. 🙂

---

<div class="post-metadata">

**Author:** ![Kai\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e95f7d/32.png) [@Kai\_H](https://www.ruby-forum.com/u/Kai_H)\
**Post date:** [August 27, 2013, 2:26pm UTC](https://www.ruby-forum.com/t/virtualdocumentroot-with-1-4-2/236330/5 "2013-08-27T14:26:22Z")

</div>

On Tue, Aug 27, 2013 at 03:32:29PM +0400, Maxim D. wrote:

> : - the user whose credentials are used by worker processes should have  
> : permissions to create files in a directory with such logs;

/var/log/nginx has +x on http user, so that’s fine.

> : - buffered writes do not work;

Not sure what that means.

> : - the file is opened and closed for each log write. However, since the  
> : descriptors of frequently used files can be stored in a cache, writing to the  
> : old file can continue during the time specified by the open\_log\_file\_cache  
> : directive’s valid parameter

IIUC there can be delay. No problem.

> : - during each log write the existence of the request’s root directory is  
> : checked, and if it does not exist the log is not created. It is thus a good  
> : idea to specify both root and access\_log on the same level:

The root is served fine…

I don’t understand how I fix my problem.

Or are you saying there isn’t a way to fix it?
