Welcome! Log In Create A New Profile

Advanced

How to turn off fastcgi for one directory? Or alternatively, rewrite a rule...

Posted by raindog308 
How to turn off fastcgi for one directory? Or alternatively, rewrite a rule...
March 06, 2012 04:06PM
I was given a rewrite rule from a vendor who assumes that everyone is running Apache. Bad vendor! But I have to live with them.

They say:

As you are using FCGI, the standard authentication methods may not work making you unable to log in. To resolve this,
create a new file called .htaccess in your forums root directory and add the following code. If you already have a .htaccess file,
add this to the bottom.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>

This is to enable WebDav, which otherwise fails.

I started down the path of saying "well, let's write an nginx matching rule" - but then I realized this is only the admin section and who cares if it's a little slower for me, the one admin who uses it rarely.

So how can I turn off fastcgi for one directory, but leave it on for others?

Tried this...but it resulted in the .php downloading as a text file instead of being run through php:

location ^~ /admin/ {
# do not process fastcgi
root /www.example.org/html;
index index.php index.html;
try_files $uri $uri/ /index.php;
if (!-e $request_filename) {
rewrite . /index.php last;
}
}

# fastcgi
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/www.example.org/html$fastcgi_script_name;
}


# main definition
location / {
root /web/www.example.org/html;
index index.php index.html;
try_files $uri $uri/ /index.php;
if (!-e $request_filename) {
rewrite . /index.php last;
}
}

Or, I could write a rule. If I read the vendor's rewrite rule correctly, it's asking Apache to set an environment variable called HTTP_AUTHORIZATION to the value of the HTTP:Authorization in the query string. I am not the world's strongest Apache guy though. Perhaps because I run nginx :-)

So in my nginx server config, I thought perhaps something like this:

location ~ HTTP:Authorization {
# some magic here
}

But...

(1) I can't figure out how to match on a variable in the query string. I can write location matches for the URI, but not the query string...? I think I need some kind of if ( ) test instead, but I can't find the write condition.

(2) How do I get nginx to set an environment variable from a value in the query string?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 146
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