Welcome! Log In Create A New Profile

Advanced

Re: Understanding location blocks and try files

January 22, 2014 02:54PM
Thanks for the reply,

I've read through those sections again - if I'm missing something obvious I'm afraid I need someone to point it out to me :|

Sorry about that I thought pointing at a working example would allow close scrutiny - didn't think to remove the files/config that weren't in use. Only the mentioned location block is relevant, inlining that and the fastcgi config becomes [1]:

<pre>
server {
listen 80;
server_name nginx.dev *.nginx.dev;

access_log /tmp/access.log;
error_log /tmp/error.log debug;

error_page 404 /404.html;

root /etc/nginx/www;
index index.php index.html index.htm;

try_files $uri $uri.html /index.php?$args;

send_timeout 600s;

location ~ \.php$ {
try_files $uri =404;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

fastcgi_param HTTPS $https if_not_empty;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_intercept_errors on; # to support 404s for PHP files not found
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_read_timeout 600s;
}

location ~* \.(?:manifest|appcache|html?|xml|json)$ {
add_header section "expires.conf:13";
expires -1;
}
}
</pre>

The behavior is identical to as originally described.

A valid response where the url is a file:

$ curl -i http://nginx.dev/foo.json
HTTP/1.1 200 OK
Server: nginx/1.4.4
Date: Wed, 22 Jan 2014 19:28:34 GMT
Content-Type: application/json
Content-Length: 20
Last-Modified: Wed, 22 Jan 2014 18:01:51 GMT
Connection: keep-alive
ETag: "52e0078f-14"
Expires: Wed, 22 Jan 2014 19:28:33 GMT
Cache-Control: no-cache
section: expires.conf:13
Accept-Ranges: bytes

An invalid response when passed to php:

$ curl -i http://nginx.dev/apples.json
HTTP/1.1 404 Not Found
Server: nginx/1.4.4
Date: Wed, 22 Jan 2014 19:28:40 GMT
Content-Type: text/html
Content-Length: 8
Connection: keep-alive
ETag: "52dffeed-8"

OH DEAR

Am I missing something obvious or falling for a common misunderstanding?
Is there a way to define location blocks for static files - without that causing problems for dynamic requests for the same url pattern?

Cheers,

AD

[1] https://github.com/AD7six/server-configs-nginx/blob/location-debug/sites-available/nginx.dev
Subject Author Posted

Understanding location blocks and try files

AD7six January 22, 2014 01:31PM

Re: Understanding location blocks and try files

Jonathan Matthews January 22, 2014 02:04PM

Re: Understanding location blocks and try files

AD7six January 22, 2014 02:54PM

Re: Understanding location blocks and try files

Francis Daly January 22, 2014 03:38PM

Re: Understanding location blocks and try files

Jonathan Matthews January 22, 2014 04:08PM

Re: Understanding location blocks and try files

Valentin V. Bartenev January 22, 2014 04:32PM

Re: Understanding location blocks and try files

Francis Daly January 22, 2014 05:20PM

Re: Understanding location blocks and try files

AD7six January 23, 2014 06:54AM

Re: Understanding location blocks and try files

Francis Daly January 23, 2014 08:44PM

Re: Understanding location blocks and try files

AD7six January 24, 2014 11:17AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 234
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready