This is a really basic question. I’m unfamiliar with nginx (didn’t even
know it existed until a couple days ago) and not a master at URL
rewrites. I have been tasked with hooking up Wordpress to nginx. The
basic setup was easy enough. However, I’m running into some problems
with the rewrites. I’ve been asked to rewrite from the static permalink
format…
“/blog/$postname$-$post_id$” (e.g. /blog/my_blog_post_title-49) => to
the standard “/blog/?p=N”
I’ve tried a bunch of variations, but I keep getting it wrong because
the non-post content (css, images, etc.) are returning 404s. Does anyone
have an example of how to do a nginx rewrite that does the above?
On Mon, 2010-02-08 at 19:09 -0500, Jaime Magiera wrote:
to the standard “/blog/?p=N”
I’ve tried a bunch of variations, but I keep getting it wrong because
the non-post content (css, images, etc.) are returning 404s. Does
anyone have an example of how to do a nginx rewrite that does the
above?
You should probably setup a separate location for the static content
(images, css, etc), that way your rewrite doesn’t affect them.
Wordpress uses post_name for queries from the url. Out of the box it
only supports hyphens and not underscores. You need to also change
your permalink settings in wordpress admin Settings > Permalinks.
The rewrite only needs to use try_file conf as outlined in the
wordpress config on wiki.nginx.org. That or:
error_page 404 /index.php?q=$uri;
You can probably do something like this at best:
/blog/my-blog-post-title-49
or
/blog/my-blog-post-title-49.html
No need for symlinks, and a million ways to do things. Still need to
add in that supercache config I wrote like a year ago for someone but
I want to test it first :P~.
No need for symlinks, and a million ways to do things. Â Still need to
add in that supercache config I wrote like a year ago for someone but
I want to test it first :P~.
OK, I appreciate all your help. It seems I’ve messed things up even more
now. While attempting to translate what you folks provided, I’ve now got
a configuration that doesn’t work right even with standard wordpress
links. If I try to go to the default URL for the blog, I end up getting
a download of the php instead of the page displaying (however, some
other wordpress URLS work?). I’m really not getting nginx. Can someone
perhaps point out what it is that I’m not getting. Taking this project
over cold with no nginx experience is becoming a very frustrating
experience.
you forgot fastcgi_pass.
and QUERY_STRING is not needed.
OK, that would give me what’s copied below. However, I’m still getting a
download of the php when I navigate to /blog instead of the php content.
Every other .php file in the wordpress directory is working. Any other
thoughts? This is stumping me.
index index.php index.html;
location ~ .php$ {
fastcgi_index index.php;
fastcgi_pass localhost:9000;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include /opt/nginx/conf/fastcgi_params;
}