Showing posts with label nginx. Show all posts
Showing posts with label nginx. Show all posts

Monday, May 2, 2011

Nginx's Rewrite Rules for WordPress MS In a Subdirectory

Nginx's rewrite rules have been giving me a headache lately. Okay, cool so it doesn't support .htaccess files; that's fine. WordPress' Codex Nginx Page gives me some great information on how to do the rewrites.


Ah but I'm running WordPress in a subdirectory! My site URI for WordPress is something like, http://mydomain.com/subdir/. Okay? Yea should be fine as long as you rewrite the rewrite rules a little bit like so:

if (!-e $request_filename) {
rewrite ^/subdir/[_0-9a-zA-Z-]+(/wp-.*) /subdir$1 last;
rewrite ^/subdir/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ /subdir$1 last;
rewrite ^/subdir/[_0-9a-zA-Z-]+(/.*\.php)$ /subdir$1 last;
}


That wasn't so bad right? Yea, it confused the heck out of me though at first! So hopefully the next person won't have the same headaches! Cheers!

Thursday, April 28, 2011

Nginx: Running FastCGI Under an Alias

So yay, Nginx has been a new playground for me here. It's awesome thus far and I love the process management! I've still got a bunch of exploring to do and I'm super busy, so excuse the brevity!


FastCGI Issues With Aliases

I've scoured the web for help on this one and it seems like a common issue that people have had. Check out the comment section on this post for a good starting point on this issue. But the usual trial and error was what ultimately got everything working for me.


Here's what I got working for me below:

location /dir/ {
alias /usr/local/www/foo/;
index index.php;
}

location ~ /dir/.*\.php$ {
if ($fastcgi_script_name ~ /dir(/.*\.php)$) {
set $valid_fastcgi_script_name $1;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/www/foo$valid_fastcgi_script_name;
include fastcgi_params;
}


The problem I was running into was here:
location ~ /dir/.*\.php$ {
if ($fastcgi_script_name ~ /dir(/.*\.php)$) {
set $valid_fastcgi_script_name $1;
}

I assumed $fastcgi_script_name was going to be from /foo but it was already being passed the alias (/dir).


I suppose I'm just writing this to remind me in the future, but in case this helps anyone else, hope it makes sense!


Cheers!