Help with location context?
Francis Daly
francis at daoine.org
Sat Oct 17 08:00:24 UTC 2015
On Fri, Oct 16, 2015 at 10:29:26AM -0400, de_nginx_noob wrote:
Hi there,
> So this is my nginx.conf file :
It turns out that most of this is unnecessary, if you just want to
understand the location{}s involved.
It's not a problem; but if you simplify the config then there is less
to cause confusion.
> include /etc/nginx/conf.d/*.conf;
The config now includes whatever is in those files.
If any of them has, for example, "listen 80; server_name centos-7-nginx;",
then your server{} block below will not be used by your sample request.
> server {
> listen 80 default_server;
> listen [::]:80 default_server;
> server_name _;
> root /usr/share/nginx/html;
>
> # Load configuration files for the default server block.
> include /etc/nginx/default.d/*.conf;
The config now includes whatever is in those files.
If any of them has, for example, "location = /test", then your location{}
block below will not be used by your sample request.
> location /test {
> log_format testLog 'testing test location block
> [$time_local]';
I get
nginx: [emerg] "log_format" directive is not allowed here in...
so this config never is used by a running nginx.
http://nginx.org/r/log_format says that the context for this directive is http.
Move that line to http level and reload.
> access_log /var/log/nginx/access.log testLog;
> }
>
> error_page 404 /404.html;
> location = /40x.html {
> }
> As you can see, most of it is default. I just changed the location context
> to try and do a custom log whenever someone requests something that begins
> with /test. Nginx is running on a vm called centos-7-nginx.
>
> When I try to use curl centos-7-nginx/test or when I type in
> centos-7-nginx/test in the browser, it doesn't hit that location block and
> instead logs these using the http context log command :
The documentation page above notes:
Requests are logged in the context of a location where processing ends.
> 192.168.1.48 - - [16/Oct/2015:10:27:02 -0400] "GET /test HTTP/1.1" 404 3650
> "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:41.0) Gecko/20100101
> Firefox/41.0" "2.242.71.204" --- from browser
"404" there suggests that "test" does not exist in your document root,
so a 404 error is raised. You have defined a separate location{} for
handling 404 errors, so *that* is the location where processing ends,
and the access_log directives in there are the ones that apply.
Either remove the "error_page 404" directive, or let a file or directory
called "test" exist in /usr/share/nginx/html, and re-try the test.
> I've tried = /test, /test/, test, even regex, but nothing seems to get it to
> map to /test. What am I missing here?
Your config is never actually being used because it is invalid.
Whatever nginx config reload sequence you use should alert you to that fact.
And the file that you expect to get in the response, does not exist.
f
--
Francis Daly francis at daoine.org
More information about the nginx
mailing list