Nginx - error_log for dynamic vhosts
This is simply not supported — you can use the variables within http://nginx.org/r/access_log, but not within http://nginx.org/r/error_log.
P.S. Note that in general, it's a pretty bad idea to use user-input variables within either access_log
or error_log
, since you introduce the potential for a malicious user to exhaust the inodes on your filesystem by making requests with random strings in the Host
header, which may result in creation of a new file for every new request. This could even happen inadvertently (without a malicious intent) by someone simply trying to enumerate all the possible users on your server. Your specific code doesn't necessarily suffer from this, as directories are not normally created automatically by any UNIX software, but it's still not the best way to do things.
In nginx philosophy, it'd be a better idea to generate a separate http://nginx.org/r/server config for each user (since nginx can be restarted without any downtime). Consider that it has additional benefits because nginx heavily relies on mathematically efficient datastructures for finding the correct server
(which regexp-based server configurations aren't). Not using variables within access_log
would also ensure that writes to the access_log
could be buffered, which can greatly increase the effective throughput of your server (especially if you log onto non-SSD HDDs).
Basically, there are already many bandaids in nginx to support variables within access_log
(just look at the list of limitations at http://nginx.org/r/access_log for when variables are used to specify the file), and, I guess, it was deemed inappropriate to introduce even more of such bandaids to error_log
as well (especially given that the error_log
in production scenarios is not supposed to be nearly as large as access_log
, so, if necessary, you can easily write external tools to split it out).