I want to use nginx as server in my vps, but it appears 404 error, then I reffer http://www.yiiframework.com/doc/cookbook/15/, then no 404 errors, but 502 errors appears. When I don’t use the path URL format everything is ok, So I don’t think it’s caused by the nginx configuration. Anybody have ideas about it?
I also have an additional location block specifically for serving php files (they get passed to a fastcgi process listening on port 9000; php-fpm). If you need to see that as well, let me know
Yep, even though you have a \.php location block to pass scripts to the fastcgi process, you still need a root location block (or wherever Yii’s top-most index.php is) to give Yii a chance to do it’s routing, and that means
rewrite ^/(.+)$ /index.php?url=$1 last;
This passes the requested URI (your controller and action names) to ‘index.php’ in your webroot in what is apparently the only rewrite rule I could get to work (and I tried all variations).
Since nginx applies logic to URI’s in the order of the location blocks as listed in your nginx.conf, you may need to position the root location block after your /blog location block, unless of course that is the yii web root, in which case you should change the rewrite rule to the one above.
I believe nginx is smart enough to know that if you have a location block that is something other than ‘/’ (yours is /blog’) it assumes the URI is then anything after the location. So in your case, anything after ‘/blog’ is the URI, and if that is the case, then the same rewrite rule above will work in your /blog location.
If that doesn’t work, try this rewrite rule for the /blog location block:
rewrite ^/(.+)$ /blog/index.php?url=$1 last;
…similar to yours except the regex is different and the ‘url=’ appendage is required for me. I could not get nginx to work (502s like you get) when I tried to use the simple $1 variable.