phpnginxx-accel-redirect

PHP and Nginx X-Accel-Redirect


I am trying to serve files from a non public directory and not having much fun at all.

server {

listen 80;
listen [::]:80;
root /websites/testing.com;
index index.php;

server_name testing.com;

location = /index.php{
    include fastcgi.conf;
}

location ~ ^/download/ {
        internal;
        alias   /websites/testing.com/protected;
    }
}

My index.php looks like

<?php
header('Cache-Control: public, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename=sample-text.txt');
header('Content-Transfer-Encoding: binary');
header("X-Accel-Redirect: /download/sample-text.txt");
?>

My folder structure is

/websites/testing.com/index.php
/websites/testing.com/protected/sample-text.txt

My host file contains the line 139.59.33.22 testing.com. But when I visit testing.com/index.php instead of being offered a file for dowload I get redirected to http://testing.com/download/sample-text.txt/

My nginx debug log is

2016/12/05 15:31:35 [debug] 23974#23974: *39309 accept: 

81.150.42.156:61315 fd:4 2016/12/05 15:31:35 [debug] 23974#23974: *39309 event timer add: 4: 60000:1480951955868 2016/12/05 15:31:35 [debug] 23974#23974: *39309 reusable connection: 1 2016/12/05 15:31:35 [debug] 23974#23974: *39309 epoll add event: fd:4 op:1 ev:80002001 2016/12/05 15:31:35 [debug] 23974#23974: *39309 post event 00005620B1A50D30 2016/12/05 15:31:35 [debug] 23974#23974: *39309 delete posted event 00005620B1A50D30 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http wait request handler 2016/12/05 15:31:35 [debug] 23974#23974: *39309 malloc: 00005620B19CD9C0:1024 2016/12/05 15:31:35 [debug] 23974#23974: *39309 recv: fd:4 334 of 1024 2016/12/05 15:31:35 [debug] 23974#23974: *39309 reusable connection: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 posix_memalign: 00005620B1A28CE0:4096 @16 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http process request line 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http request line: "GET /index.php HTTP/1.1" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http uri: "/index.php" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http args: "" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http exten: "php" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 posix_memalign: 00005620B1A35640:4096 @16 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http process request header line 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http header: "Host: testing.com" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http header: "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:49.0) Gecko/20100101 Firefox/49.0" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http header: "Accept-Language: en-GB,en;q=0.5" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http header: "Accept-Encoding: gzip, deflate" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http header: "Connection: keep-alive" 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http header: "Upgrade-Insecure-Requests: 1" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http header done 2016/12/05 15:31:35 [debug] 23974#23974: *39309 event timer del: 4: 1480951955868 2016/12/05 15:31:35 [debug] 23974#23974: *39309 generic phase: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 rewrite phase: 1 2016/12/05 15:31:35 [debug] 23974#23974: *39309 test location: "/index.php" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 using configuration "=/index.php" 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http cl:-1 max:1048576 2016/12/05 15:31:35 [debug] 23974#23974: *39309 rewrite phase: 3 2016/12/05 15:31:35 [debug] 23974#23974: *39309 post rewrite phase: 4 2016/12/05 15:31:35 [debug] 23974#23974: *39309 generic phase: 5 2016/12/05 15:31:35 [debug] 23974#23974: *39309 generic phase: 6 2016/12/05 15:31:35 [debug] 23974#23974: *39309 generic phase: 7 2016/12/05 15:31:35 [debug] 23974#23974: *39309 access phase: 8 2016/12/05 15:31:35 [debug] 23974#23974: *39309 access phase: 9 2016/12/05 15:31:35 [debug] 23974#23974: *39309 access phase: 10 2016/12/05 15:31:35 [debug] 23974#23974: *39309 post access phase: 11 2016/12/05 15:31:35 [debug] 23974#23974: *39309 try files phase: 12 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http init upstream, client timer: 0 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 epoll add event: fd:4 op:3 ev:80002005 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "SCRIPT_FILENAME" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script var: "/websites/testing.com" 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http script var: "/index.php" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "SCRIPT_FILENAME: /websites/testing.com/index.php" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "QUERY_STRING" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "QUERY_STRING: " 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "REQUEST_METHOD" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script var: "GET" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "REQUEST_METHOD: GET" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "CONTENT_TYPE" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "CONTENT_TYPE: " 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "CONTENT_LENGTH" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "CONTENT_LENGTH: " 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "SCRIPT_NAME" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script var: "/index.php" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "SCRIPT_NAME: /index.php" 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http script copy: "REQUEST_URI" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script var: "/index.php" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "REQUEST_URI: /index.php" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "DOCUMENT_URI" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script var: "/index.php" 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 fastcgi param: "DOCUMENT_URI: /index.php" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "DOCUMENT_ROOT" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script var: "/websites/testing.com" 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 fastcgi param: "DOCUMENT_ROOT: /websites/testing.com" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "SERVER_PROTOCOL" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script var: "HTTP/1.1" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "SERVER_PROTOCOL: HTTP/1.1" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "REQUEST_SCHEME" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script var: "http" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "REQUEST_SCHEME: http" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "GATEWAY_INTERFACE" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "CGI/1.1" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "GATEWAY_INTERFACE: CGI/1.1" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "SERVER_SOFTWARE" 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http script copy: "nginx/" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script var: "1.10.0" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "SERVER_SOFTWARE: nginx/1.10.0" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "REMOTE_ADDR" 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http script var: "81.150.42.156" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "REMOTE_ADDR: 81.150.42.156" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "REMOTE_PORT" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script var: "61315" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "REMOTE_PORT: 61315" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "SERVER_ADDR" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script var: "10.16.0.5" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "SERVER_ADDR: 10.16.0.5" 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http script copy: "SERVER_PORT" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script var: "80" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "SERVER_PORT: 80" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "SERVER_NAME" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script var: "testing.com" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "SERVER_NAME: testing.com" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "REDIRECT_STATUS" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "200" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "REDIRECT_STATUS: 200" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "HTTP_HOST: testing.com" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:49.0) Gecko/20100101 Firefox/49.0" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "HTTP_ACCEPT_LANGUAGE: en-GB,en;q=0.5" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "HTTP_ACCEPT_ENCODING: gzip, deflate" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "HTTP_CONNECTION: keep-alive" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 fastcgi param: "HTTP_UPGRADE_INSECURE_REQUESTS: 1" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http cleanup add: 00005620B1A36160 2016/12/05 15:31:35 [debug] 23974#23974: *39309 get rr peer, try: 1 2016/12/05 15:31:35 [debug] 23974#23974: *39309 stream socket 5 2016/12/05 15:31:35 [debug] 23974#23974: *39309 epoll add connection: fd:5 ev:80002005 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 connect to unix:/run/php/php7.0-fpm.sock, fd:5 #39310 2016/12/05 15:31:35 [debug] 23974#23974: *39309 connected 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http upstream connect: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 posix_memalign: 00005620B19C4FB0:128 @16 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http upstream send request 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http upstream send request body 2016/12/05 15:31:35 [debug] 23974#23974: *39309 chain writer buf fl:0 s:816 2016/12/05 15:31:35 [debug] 23974#23974: *39309 chain writer in: 00005620B1A36198 2016/12/05 15:31:35 [debug] 23974#23974: *39309 writev: 816 of 816 2016/12/05 15:31:35 [debug] 23974#23974: *39309 chain writer out: 0000000000000000 2016/12/05 15:31:35 [debug] 23974#23974: *39309 event timer add: 5: 60000:1480951955872 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http finalize request: -4, "/index.php?" a:1, c:2 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http request count:2 blk:0 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 post event 00005620B1A0BB60 2016/12/05 15:31:35 [debug] 23974#23974: *39309 post event 00005620B1A0BC20 2016/12/05 15:31:35 [debug] 23974#23974: *39309 delete posted event 00005620B1A0BB60 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http run request: "/index.php?" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http upstream check client, write event:1, "/index.php" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http upstream recv(): -1 (11: Resource temporarily unavailable) 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 delete posted event 00005620B1A0BC20 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http upstream request: "/index.php?" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http upstream dummy handler 2016/12/05 15:31:35 [debug] 23974#23974: *39309 post event 00005620B1A50DF0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 post event 00005620B1A0BC20 2016/12/05 15:31:35 [debug] 23974#23974: *39309 delete posted event 00005620B1A50DF0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http upstream request: "/index.php?" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http upstream process header 2016/12/05 15:31:35 [debug] 23974#23974: *39309 malloc: 00005620B1A039C0:4096 2016/12/05 15:31:35 [debug] 23974#23974: *39309 recv: fd:5 256 of 4096 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi record byte: 01 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http fastcgi record byte: 06 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi record byte: 00 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi record byte: 01 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi record byte: 00 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi record byte: E6 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi record byte: 02 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi record byte: 00 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http fastcgi record length: 230 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi parser: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi header: "Cache-Control: public, must-revalidate" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi parser: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi header: "Pragma: no-cache" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi parser: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi header: "Content-type: text/plain;charset=UTF-8" 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http fastcgi parser: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi header: "Content-Disposition: attachment; filename=Heyhoe" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi parser: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi header: "Content-Transfer-Encoding: binary" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi parser: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi header: "X-Accel-Redirect: /download/sample-text.txt" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi parser: 1 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http fastcgi header done 2016/12/05 15:31:35 [debug] 23974#23974: *39309 finalize http upstream request:
-5 2016/12/05 15:31:35 [debug] 23974#23974: *39309 finalize http fastcgi request 2016/12/05 15:31:35 [debug] 23974#23974: *39309 free rr peer 1 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 close http upstream connection: 5 2016/12/05 15:31:35 [debug] 23974#23974: *39309 free: 00005620B19C4FB0, unused: 48 2016/12/05 15:31:35 [debug] 23974#23974: *39309 event timer del: 5: 1480951955872 2016/12/05 15:31:35 [debug] 23974#23974: *39309 delete posted event 00005620B1A0BC20 2016/12/05 15:31:35 [debug] 23974#23974: *39309 reusable connection: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 internal redirect: "/download/sample-text.txt?" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 rewrite phase: 1 2016/12/05 15:31:35 [debug] 23974#23974: *39309 test location: "/index.php" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 test location: ~ "^/download/" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 using configuration "^/download/" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http cl:-1 max:1048576 2016/12/05 15:31:35 [debug] 23974#23974: *39309 rewrite phase: 3 2016/12/05 15:31:35 [debug] 23974#23974: *39309 post rewrite phase: 4 2016/12/05 15:31:35 [debug] 23974#23974: *39309 generic phase: 5 2016/12/05 15:31:35 [debug] 23974#23974: *39309 generic phase: 6 2016/12/05 15:31:35 [debug] 23974#23974: *39309 generic phase: 7 2016/12/05 15:31:35 [debug] 23974#23974: *39309 access phase: 8 2016/12/05 15:31:35 [debug] 23974#23974: *39309 access phase: 9 2016/12/05 15:31:35 [debug] 23974#23974: *39309 access phase: 10 2016/12/05 15:31:35 [debug] 23974#23974: *39309 post access phase: 11 2016/12/05 15:31:35 [debug] 23974#23974: *39309 try files phase: 12 2016/12/05 15:31:35 [debug] 23974#23974: *39309 content phase: 13 2016/12/05 15:31:35 [debug] 23974#23974: *39309 content phase: 14 2016/12/05 15:31:35 [debug] 23974#23974: *39309 content phase: 15 2016/12/05 15:31:35 [debug] 23974#23974: *39309 content phase: 16 2016/12/05 15:31:35 [debug] 23974#23974: *39309 content phase: 17 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http script copy: "/websites/testing.com/protected" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http filename: "/websites/testing.com/protected" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 add cleanup: 00005620B1A364B0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http static fd: -1 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http dir 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http finalize request: 301, "/download/sample-text.txt?" a:1, c:2 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http special response: 301, "/download/sample-text.txt?" 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 xslt filter header 2016/12/05 15:31:35 [debug] 23974#23974: *39309 posix_memalign: 00005620B1A049D0:4096 @16 2016/12/05 15:31:35 [debug] 23974#23974: *39309 HTTP/1.1 301 Moved Permanently

Server: nginx/1.10.0 (Ubuntu)

Date: Mon, 05 Dec 2016 15:31:35 GMT

Content-Type: text/html; charset=UTF-8

Content-Length: 194

Location: http://testing.com/download/sample-text.txt/

Connection: keep-alive

Cache-Control: public, must-revalidate

Content-Disposition: attachment; filename=Heyhoe


2016/12/05 15:31:35 [debug] 23974#23974: *39309 write new buf t:1 f:0 00005620B1A049F0, pos 00005620B1A049F0, size: 333 file: 0, size: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http write filter: l:0 f:0 s:333 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http output filter "/download/sample-text.txt?" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http copy filter: "/download/sample-text.txt?" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 image filter 2016/12/05 15:31:35 [debug] 23974#23974: *39309 xslt filter body 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http postpone filter "/download/sample-text.txt?" 00005620B1A36620 2016/12/05 15:31:35 [debug] 23974#23974: *39309 write old buf t:1 f:0 00005620B1A049F0, pos 00005620B1A049F0, size: 333 file: 0, size: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 write new buf t:0 f:0 0000000000000000, pos 00005620B131DAC0, size: 132 file: 0, size: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 write new buf t:0 f:0 0000000000000000, pos 00005620B131DDA0, size: 62 file: 0, size: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http write filter: l:1 f:0 s:527 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http write filter limit 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 writev: 527 of 527 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http write filter 0000000000000000 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http copy filter: 0 "/download/sample-text.txt?" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http finalize request: 0, "/download/sample-text.txt?" a:1, c:2 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http request count:2 blk:0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http finalize request: -4, "/download/sample-text.txt?" a:1, c:1 2016/12/05 15:31:35 [debug] 23974#23974: *39309 set http keepalive handler 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http close request 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http log handler 2016/12/05 15:31:35 [debug] 23974#23974: *39309 free: 00005620B1A039C0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 free: 00005620B1A28CE0, unused: 8 2016/12/05 15:31:35 [debug] 23974#23974: *39309 free: 00005620B1A35640, unused: 0 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 free: 00005620B1A049D0, unused: 3356 2016/12/05 15:31:35 [debug] 23974#23974: *39309 free: 00005620B19CD9C0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 hc free: 0000000000000000 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 hc busy: 0000000000000000 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 tcp_nodelay 2016/12/05 15:31:35 [debug] 23974#23974: *39309 reusable connection: 1 2016/12/05 15:31:35 [debug] 23974#23974: *39309 event timer add: 4: 65000:1480951960874 2016/12/05 15:31:35 [debug] 23974#23974: *39309 post event 00005620B1A50D30 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 delete posted event 00005620B1A50D30 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http keepalive handler 2016/12/05 15:31:35 [debug] 23974#23974: *39309 malloc: 00005620B19CD9C0:1024 2016/12/05 15:31:35 [debug] 23974#23974: *39309 recv: fd:4 -1 of 1024 2016/12/05 15:31:35 [debug] 23974#23974: *39309 recv() not ready (11: Resource temporarily unavailable) 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 free: 00005620B19CD9C0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 post event 00005620B1A50D30 2016/12/05 15:31:35 [debug] 23974#23974: *39309 post event 00005620B1A0BB60 2016/12/05 15:31:35 [debug] 23974#23974: *39309 delete posted event 00005620B1A50D30 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http keepalive handler 2016/12/05 15:31:35 [debug] 23974#23974: *39309 malloc: 00005620B19CD9C0:1024 2016/12/05 15:31:35 [debug] 23974#23974: *39309 recv: fd:4 350 of 1024 2016/12/05 15:31:35 [debug] 23974#23974: *39309 reusable connection: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 posix_memalign: 00005620B1A28CE0:4096 @16 2016/12/05 15:31:35 [debug] 23974#23974: *39309 event timer del: 4: 1480951960874 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http process request line 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http request line: "GET /download/sample-text.txt/ HTTP/1.1" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http uri: "/download/sample-text.txt/" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http args: "" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http exten: "" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 posix_memalign: 00005620B1A35640:4096 @16 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http process request header line 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http header: "Host: testing.com" 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http header: "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:49.0) Gecko/20100101 Firefox/49.0" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http header: "Accept-Language: en-GB,en;q=0.5" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http header: "Accept-Encoding: gzip, deflate" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http header: "Connection: keep-alive" 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http header: "Upgrade-Insecure-Requests: 1" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http header done 2016/12/05 15:31:35 [debug] 23974#23974: *39309 generic phase: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 rewrite phase: 1 2016/12/05 15:31:35 [debug] 23974#23974: *39309 test location: "/index.php" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 test location: ~ "^/download/" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http finalize request: 404, "/download/sample-text.txt/?" a:1, c:1 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http special response: 404, "/download/sample-text.txt/?" 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 http set discard body 2016/12/05 15:31:35 [debug] 23974#23974: *39309 xslt filter header 2016/12/05 15:31:35 [debug] 23974#23974: *39309 HTTP/1.1 404 Not Found

Server: nginx/1.10.0 (Ubuntu)

Date: Mon, 05 Dec 2016 15:31:35 GMT

Content-Type: text/html

Transfer-Encoding: chunked

Connection: keep-alive

Content-Encoding: gzip


2016/12/05 15:31:35 [debug] 23974#23974: *39309 write new buf t:1 f:0 00005620B1A29B80, pos 00005620B1A29B80, size: 195 file: 0, size: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http write filter: l:0 f:0 s:195 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http output filter "/download/sample-text.txt/?" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http copy filter: "/download/sample-text.txt/?" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 image filter 2016/12/05 15:31:35 [debug] 23974#23974: *39309 xslt filter body 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http postpone filter "/download/sample-text.txt/?" 00005620B1A29CA8 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http gzip filter 2016/12/05 15:31:35 [debug] 23974#23974: *39309 malloc: 00005620B1A039C0:12288 2016/12/05 15:31:35 [debug] 23974#23974: *39309 gzip alloc: n:1 s:5936 a:8192 p:00005620B1A039C0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 gzip alloc: n:512 s:2 a:1024 p:00005620B1A059C0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 gzip alloc: n:512 s:2 a:1024 p:00005620B1A05DC0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 gzip alloc: n:512 s:2 a:1024 p:00005620B1A061C0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 gzip alloc: n:256 s:4 a:1024 p:00005620B1A065C0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 gzip in: 00005620B1A35AE8 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 gzip in_buf:00005620B1A29C58 ni:00005620B131D660 ai:116 2016/12/05 15:31:35 [debug] 23974#23974: *39309 malloc: 00005620B1A62BC0:4096 2016/12/05 15:31:35 [debug] 23974#23974: *39309 deflate in: ni:00005620B131D660 no:00005620B1A62BC0 ai:116 ao:4096 fl:0 redo:0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 deflate out: ni:00005620B131D6D4 no:00005620B1A62BC0 ai:0 ao:4096 rc:0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 gzip in_buf:00005620B1A29C58 pos:00005620B131D660 2016/12/05 15:31:35 [debug] 23974#23974: *39309 gzip in: 00005620B1A35AF8 2016/12/05 15:31:35 [debug] 23974#23974: *39309 gzip in_buf:00005620B1A35A20 ni:00005620B131DDA0 ai:62 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 deflate in: ni:00005620B131DDA0 no:00005620B1A62BC0 ai:62 ao:4096 fl:4 redo:0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 deflate out: ni:00005620B131DDDE no:00005620B1A62C3B ai:0 ao:3973 rc:1 2016/12/05 15:31:35 [debug] 23974#23974: *39309 gzip in_buf:00005620B1A35A20 pos:00005620B131DDA0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 free: 00005620B1A039C0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http chunk: 10 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http chunk: 131 2016/12/05 15:31:35 [debug] 23974#23974: *39309 write old buf t:1 f:0 00005620B1A29B80, pos 00005620B1A29B80, size: 195 file: 0, size: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 write new buf t:1 f:0 00005620B1A35C58, pos 00005620B1A35C58, size: 4 file: 0, size: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 write new buf t:0 f:0 0000000000000000, pos 00005620B13209E0, size: 10 file: 0, size: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 write new buf t:1 f:0 00005620B1A62BC0, pos 00005620B1A62BC0, size: 131 file: 0, size: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 write new buf t:0 f:0 0000000000000000, pos 00005620B10EFF41, size: 7 file: 0, size: 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http write filter: l:1 f:1 s:347 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http write filter limit 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 writev: 347 of 347 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http write filter 0000000000000000 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http copy filter: 0 "/download/sample-text.txt/?" 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http finalize request: 0, "/download/sample-text.txt/?" a:1, c:1 2016/12/05 15:31:35 [debug] 23974#23974: *39309 set http keepalive handler 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http close request 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http log handler 2016/12/05 15:31:35 [debug] 23974#23974: *39309 free: 00005620B1A62BC0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 free: 0000000000000000 2016/12/05 15:31:35 [debug] 23974#23974: *39309 free: 00005620B1A28CE0, unused: 8 2016/12/05 15:31:35 [debug] 23974#23974: *39309 free: 00005620B1A35640, unused: 2132 2016/12/05 15:31:35 [debug] 23974#23974: *39309 free: 00005620B19CD9C0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 hc free: 0000000000000000 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 hc busy: 0000000000000000 0 2016/12/05 15:31:35 [debug] 23974#23974: *39309 reusable connection: 1 2016/12/05 15:31:35 [debug] 23974#23974: *39309 event timer add: 4: 65000:1480951960921 2016/12/05 15:31:35 [debug] 23974#23974: *39309 post event 00005620B1A50D30 2016/12/05 15:31:35 [debug] 23974#23974:
*39309 delete posted event 00005620B1A0BB60 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http empty handler 2016/12/05 15:31:35 [debug] 23974#23974: *39309 delete posted event 00005620B1A50D30 2016/12/05 15:31:35 [debug] 23974#23974: *39309 http keepalive handler 2016/12/05 15:31:35 [debug] 23974#23974: *39309 malloc: 00005620B19CD9C0:1024 2016/12/05 15:31:35 [debug] 23974#23974: *39309 recv: fd:4 -1 of 1024 2016/12/05 15:31:35 [debug] 23974#23974: *39309 recv() not ready (11: Resource temporarily unavailable) 2016/12/05 15:31:35 [debug] 23974#23974: *39309 free: 00005620B19CD9C0

Solution

  • The regular expression location needs to capture the URI for the alias directive. See an example here.

    However, the simpler prefix location block should suffice:

    location /download {
        internal;
        alias   /websites/testing.com/protected;
    }
    

    Note that for correct operation, either both the location URI and the alias pathname should end with a slash (or neither end with a slash).