Opened 5 years ago

Closed 4 years ago

#916 closed defect (worksforme)

Incorrect map value passed.

Reported by: plutocrat@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.9.x
Keywords: Cc:
uname -a: Linux sxxxxxxxxw 3.2.0-4-amd64 #1 SMP Debian 3.2.73-2+deb7u2 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.8.1
built with OpenSSL 1.0.1e 11 Feb 2013
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt=-Wl,-z,relro --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_gunzip_module --with-file-aio --with-threads --with-http_spdy_module --with-http_geoip_module --with-http_gzip_static_module --without-mail_pop3_module --without-mail_smtp_module --without-mail_imap_module --without-http_uwsgi_module --without-http_scgi_module --add-module=/usr/src/builddir/debian/modules/naxsi/naxsi_src --add-module=/usr/src/builddir/debian/modules/nginx-cache-purge --add-module=/usr/src/builddir/debian/modules/nginx-upstream-fair --add-module=/usr/src/builddir/debian/modules/nginx-echo --add-module=/usr/src/builddir/debian/modules/nginx-x-rid-header --with-ld-opt=-lossp-uuid

Description

Hi,
I'm running a Wordpress Multisite instance, and have used the suggested mapping scheme in it. Mine looks like this.

map $http_host $blogid {
        default 2;
        domain1.com 1;
        temp2.domain1.com 2;
        domain2.com 2;
        temp3.domain1.com 3;
        domain3.com 3;
	.... etc ....
        temp11.domain1.com 11;
        domain11.com 11;
        .... etc ....
        temp17.domain1.com 17;
        domain17.com 17;
}

Later on in the config, I use it like this:

location ~ ^/wp-content/uploads/(.*)$ {
        try_files /wp-content/uploads/sites/$blogid/$1 /wp-content/uploads/$1  /wp-includes/ms-files.php?file=$1 ;
        access_log off; log_not_found off; expires max;
}

This was previously working OK: If the file
domain3.com/wp-content/uploads/2014/12/test.pdf
was requested, then the file from
domain3.com/wp-content/uploads/sites/3/2014/12/test.pdf
would be served

I was experiencing problems with this on one site, domain11.com. I turned on debugging in the logs and found that it actually seemed to be mapping domain11.com to $blogid=1 instead of blogid=11.

2016/03/02 03:34:07 [debug] 16139#16139: *566496 http map started
2016/03/02 03:34:07 [debug] 16139#16139: *566496 http script var: "domain11.com"
2016/03/02 03:34:07 [debug] 16139#16139: *566496 http map: "domain11.com" "1"
2016/03/02 03:34:07 [debug] 16139#16139: *566496 http script copy: "/wp-content/uploads/sites/"
2016/03/02 03:34:07 [debug] 16139#16139: *566496 http script var: "1"
2016/03/02 03:34:07 [debug] 16139#16139: *566496 http script copy: "/"
2016/03/02 03:34:07 [debug] 16139#16139: *566496 http script capture: "2014/12/test.pdf"
2016/03/02 03:34:07 [debug] 16139#16139: *566496 trying to use file: "/wp-content/uploads/sites/1/2014/12/test.pdf" "/home/user/domains/domain1.com/public_html/wp-content/uploads/sites/1/2014/12/test.pdf"

So is this a bug, or have I just misunderstood the map format? Is there a workaround?
I tried uncommenting the other $blogid=11 (ie. temp11.domain1.com). That didn't fix it.
I tried putting "" around the value 11 in the map. That didn't fix it.

Change History (2)

comment:1 by Maxim Dounin, 5 years ago

Configuration you've provided works fine as expected:

2016/03/02 15:56:16 [debug] 47760#100275: *1 http script var: "domain11.com"
2016/03/02 15:56:16 [debug] 47760#100275: *1 http map: "domain11.com" "11"
2016/03/02 15:56:16 [debug] 47760#100275: *1 http script copy: "/wp-content/uploads/sites/"
2016/03/02 15:56:16 [debug] 47760#100275: *1 http script var: "11"
2016/03/02 15:56:16 [debug] 47760#100275: *1 http script copy: "/"
2016/03/02 15:56:16 [debug] 47760#100275: *1 http script capture: "foo.gif"

Most likely, there is some problem in your configuration, e.g., a regex matching domain11.com. Please provide full and unmodified map{} snippet, as the same but unmodified debug log snippet.

If you want to keep some information private, please reproduce the problem on a test configuration with test names and again provide unmodified snippets which demonstrate the problem.

comment:2 by Maxim Dounin, 4 years ago

Resolution: worksforme
Status: newclosed

Feedback timeout.

Note: See TracTickets for help on using tickets.