nginx fastcgi 通用配置

通用配置文件php和php_upstream放在和nginx.conf同级目录。

php:

if (!-e $request_filename) {
    rewrite  ^/(.*)$  /index.php/$1 last;
}
location ~* \.php($|/) {
    include fastcgi_params;
    fastcgi_pass php;
    fastcgi_param SCRIPT_FILENAME   $request_filename;
}

php_upstream:

upstream php {
    server 127.0.0.1:9000;
    keepalive 16;
}

常规server配置

server {
    listen 80;
    server_name xxx.com;
    root /srv/www/xxx.com/public;

    include php;
}

带location的server配置

server {
    listen 80;
    server_name xxx.com;

    location / {
        root /srv/www/xxx.com/public;
        include php;
    }
    location /api {
        alias /srv/www/xxx.com-api/public;
        if (!-e $request_filename) {
            rewrite  ^/api/(.*)$  /api/index.php/$1 last;
        }
        include php;
    }
}

其中rewrite有需要特别注意的地方:last和break
这两个参数官方文档写的不是很容易理解,参考资料:
nginx rewrite 相关问题详解
http://blog.csdn.net/brainkick/article/details/7475770

发表评论

电子邮件地址不会被公开。

*