Skip to content

Instantly share code, notes, and snippets.

@AD7six
Last active August 29, 2015 14:10
Show Gist options
  • Save AD7six/b083cbdddb3f46a21dd9 to your computer and use it in GitHub Desktop.
Save AD7six/b083cbdddb3f46a21dd9 to your computer and use it in GitHub Desktop.
Is try-files significantly worse than using "does file exist?" checks? Does it "only lead[s] to disk iops saturation"?
server {
listen 80 default_server;
root /var/www/try-files-v-file-exists.com;
location ~* /try-files {
try_files $uri /tried.html;
}
location ~* /file-exists {
if (!-e $request_filename) {
rewrite ^ /missing.html;
}
}
}
$ curl http://192.168.0.74/try-files/asdf
tried
$ curl http://192.168.0.74/file-exists/asdf
missing
$
# strace -p 18237
Process 18237 attached
gettimeofday({1416669659, 374193}, NULL) = 0
epoll_wait(6, {{EPOLLIN, {u32=3143286800, u64=140710566871056}}}, 512, -1) = 1
gettimeofday({1416669665, 497489}, NULL) = 0
accept4(7, {sa_family=AF_INET, sin_port=htons(64401), sin_addr=inet_addr("192.168.0.171")}, [16], SOCK_NONBLOCK) = 3
epoll_ctl(6, EPOLL_CTL_ADD, 3, {EPOLLIN|EPOLLRDHUP|EPOLLET, {u32=3143287881, u64=140710566872137}}) = 0
epoll_wait(6, {{EPOLLIN, {u32=3143287881, u64=140710566872137}}}, 512, 60000) = 1
gettimeofday({1416669665, 502437}, NULL) = 0
recvfrom(3, "GET /try-files/asdf HTTP/1.1\r\nUs"..., 1024, 0, NULL, NULL) = 90
stat("/var/www/try-files-v-file-exists.com/try-files/asdf", 0x7fff5b148b00) = -1 ENOENT (No such file or directory)
open("/var/www/try-files-v-file-exists.com/tried.html", O_RDONLY|O_NONBLOCK) = 11
fstat(11, {st_mode=S_IFREG|0644, st_size=6, ...}) = 0
setsockopt(3, SOL_TCP, TCP_CORK, [1], 4) = 0
writev(3, [{"HTTP/1.1 200 OK\r\nServer: nginx\r\n"..., 227}], 1) = 227
sendfile(3, 11, [0], 6) = 6
write(15, "192.168.0.171 - - [22/Nov/2014:1"..., 106) = 106
close(11) = 0
setsockopt(3, SOL_TCP, TCP_CORK, [0], 4) = 0
recvfrom(3, 0xb6b600, 1024, 0, 0, 0) = -1 EAGAIN (Resource temporarily unavailable)
epoll_wait(6, {{EPOLLIN|EPOLLRDHUP, {u32=3143287881, u64=140710566872137}}}, 512, 20000) = 1
gettimeofday({1416669665, 536619}, NULL) = 0
recvfrom(3, "", 1024, 0, NULL, NULL) = 0
close(3) = 0
epoll_wait(6,
# strace -p 18237
Process 18237 attached
gettimeofday({1416669689, 211988}, NULL) = 0
epoll_wait(6, {{EPOLLIN, {u32=3143286800, u64=140710566871056}}}, 512, -1) = 1
gettimeofday({1416669696, 349272}, NULL) = 0
accept4(7, {sa_family=AF_INET, sin_port=htons(64404), sin_addr=inet_addr("192.168.0.171")}, [16], SOCK_NONBLOCK) = 3
epoll_ctl(6, EPOLL_CTL_ADD, 3, {EPOLLIN|EPOLLRDHUP|EPOLLET, {u32=3143287880, u64=140710566872136}}) = 0
epoll_wait(6, {{EPOLLIN, {u32=3143287880, u64=140710566872136}}}, 512, 60000) = 1
gettimeofday({1416669696, 354385}, NULL) = 0
recvfrom(3, "GET /file-exists/asdf HTTP/1.1\r\n"..., 1024, 0, NULL, NULL) = 92
stat("/var/www/try-files-v-file-exists.com/file-exists/asdf", 0x7fff5b148b80) = -1 ENOENT (No such file or directory)
open("/var/www/try-files-v-file-exists.com/missing.html", O_RDONLY|O_NONBLOCK) = 11
fstat(11, {st_mode=S_IFREG|0644, st_size=8, ...}) = 0
setsockopt(3, SOL_TCP, TCP_CORK, [1], 4) = 0
writev(3, [{"HTTP/1.1 200 OK\r\nServer: nginx\r\n"..., 227}], 1) = 227
sendfile(3, 11, [0], 8) = 8
write(15, "192.168.0.171 - - [22/Nov/2014:1"..., 108) = 108
close(11) = 0
setsockopt(3, SOL_TCP, TCP_CORK, [0], 4) = 0
recvfrom(3, 0xb6b600, 1024, 0, 0, 0) = -1 EAGAIN (Resource temporarily unavailable)
epoll_wait(6, {{EPOLLIN|EPOLLRDHUP, {u32=3143287880, u64=140710566872136}}}, 512, 20000) = 1
gettimeofday({1416669696, 396303}, NULL) = 0
recvfrom(3, "", 1024, 0, NULL, NULL) = 0
close(3) = 0
epoll_wait(6,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment