"index" directive not working with dynamic server_name

Maxim Dounin mdounin at mdounin.ru
Thu Dec 16 04:16:54 MSK 2010


Hello!

On Tue, Dec 14, 2010 at 06:23:36AM -0500, eckstac wrote:

> I recently upgraded to nginx 0.8.53 as it has support for regular
> expressions in the server_name directive.
> 
> However, when using this, the index directive gets ignored and a
> directory listing is displayed.
> 
> I've included part of the file which is causing the problem below.
> Essentially, when I visit a host matched by the server_name, I get a
> directory listing. One of the files in the directory is index.php -
> which is set as one of the "indexes".
> 
> Has anyone experienced similar issues to this?
> 
> server {
>         server_name ~^staging-(?P.+)\.(?P.+)\.com$;
>         root
> /var/www/htdocs/site1/staging/$domain-staging-$version/public/;
> 
>         autoindex on;
> 
>         error_log /var/log/nginx/site1-staging.error.log info

-         error_log /var/log/nginx/site1-staging.error.log info
+         error_log /var/log/nginx/site1-staging.error.log info;

> 
>         index index.php index.html index.htm;

You have no ";" after error_log directive, so "index index.php 
index.html index.htm" are interpreted as log levels.

Attached patch improves error_log parser to actually complain on 
invalid log levels.  I.e. your config will report error on 
startup/test instaed of silently eating index directive.

Maxim Dounin
-------------- next part --------------
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1292461925 -10800
# Node ID b4fd734aa6be654a9555c8b9ae5e108b233cfe37
# Parent  f02ddde4a240628b002b3fc85aa19bb38e7c5d85
Complain on invalid log levels.

Previously only first log level were required to be correct, while error_log
directive in fact accepts list of levels (e.g. one may specify "error_log ...
debug_core debug_http;").  This resulted in (avoidable) wierd behaviour on
missing semicolon after error_log directive, e.g.

error_log /path/to/log info
index index.php;

silently skipped index directive and it's arguments (trying to interpret
them as log levels without checking to be correct).

diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -369,12 +369,13 @@ ngx_log_create(ngx_cycle_t *cycle, ngx_s
 char *
 ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
 {
-    ngx_uint_t   i, n, d;
+    ngx_uint_t   i, n, d, found;
     ngx_str_t   *value;
 
     value = cf->args->elts;
 
     for (i = 2; i < cf->args->nelts; i++) {
+        found = 0;
 
         for (n = 1; n <= NGX_LOG_DEBUG; n++) {
             if (ngx_strcmp(value[i].data, err_levels[n].data) == 0) {
@@ -387,7 +388,8 @@ ngx_log_set_levels(ngx_conf_t *cf, ngx_l
                 }
 
                 log->log_level = n;
-                continue;
+                found = 1;
+                break;
             }
         }
 
@@ -401,11 +403,13 @@ ngx_log_set_levels(ngx_conf_t *cf, ngx_l
                 }
 
                 log->log_level |= d;
+                found = 1;
+                break;
             }
         }
 
 
-        if (log->log_level == 0) {
+        if (!found) {
             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                "invalid log level \"%V\"", &value[i]);
             return NGX_CONF_ERROR;


More information about the nginx mailing list