I'm trying to setup nginx in order to match certain URL on server where conditional access is granted (i.e. only those with valid client certificate are allowed to access this area).
Right now, simple location block works fine preventing access to unauthorized users:
location ~ ^/protected/ticketing {
if ($ssl_client_verify != SUCCESS) { return 401; }
#need treatment of php files here after SUCCESS = $ssl_client_verify ?!
}
So no one can access /protected/ticketing/anyThingHere
BUT. When you actually present a valid certificate, and this return 401 does not trigger, /protected/ticketing/index.php is not parsed by an upstream FPM server but instead is presented for download (i.e. content disposition is set to default octet stream).
Is there an elegant way of doing this?
My upstream is defined as:
upstream backend {
server unix:/var/run/php5-fpm.sock;
}
PHP handler location block:
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name){return 404;}
fastcgi_pass backend; #pass request to the upstream
fastcgi_index index.php;
include fastcgi_params;
}
try_files $uri $uri/ =404;into your^/protected/ticketingsection? It sends you file, because your sections are not inherit and if request is catched with ticketing, that wont be processed with further locations by-default.Accept-Ranges: bytes Connection: keep-alive Content-Length: 19581 Content-Type: application/octet-stream Date: Thu, 17 Mar 2016 16:18:29 GMT Etag: "55e0699c-4c7d" Last-Modified: Fri, 28 Aug 2015 14:01:00 GMT Server: nginx