ufcms:从windows/apache转到linux/nginx

关联链接:

ufcms:yii based cms system programming notes


主要有两点:

1. 需要把apache vhost的配置改为nginx vhost的配置

2. 需要把.htaccess文件修改为符合nginx语法规则的文件


nginx vhost配置参考如下:

    server {
        listen       80;
        server_name  open.iefreer.org;
        index index.html index.htm index.php;
        access_log   /var/log/nginx/td.access.log  access;
        error_log  /var/log/nginx/cms.error.log error;
        root  /home/www/phpsite/cms;
        include /home/www/phpsite/cms/.htaccess;

        location ~ /(protected|framework|themes/\w+/views|docs\.php) {
                deny all;
                # for production
                internal;
                log_not_found off;
                access_log off;
        }
        location ~ \.php$ {
                fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

        location ~ /(\.svn|\.git|\.DS) {
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires 30d;
                log_not_found off;
        }
    }

cms/.htaccess在apache下是:

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteBase /

#Admin
RewriteRule ^admin$ index.php?r=Cms/admin/home
#Install
RewriteRule ^install$ install.php?r=Install/default

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.(js|ico|gif|jpg|png|css)$

# otherwise forward it to index.php
RewriteRule ^.*$ /index.php [L]

可通过在线工具进行Rewrite Rule转换:

http://www.anilcetin.com/convert-apache-htaccess-to-nginx/

nginx的规则很简洁, 结果如下:

rewrite ^/admin$ /index.php?r=Cms/admin/home;
rewrite ^/install$ /install.php?r=Install/default;
rewrite ^/.*$ /index.php last;

如果上述规则不配置好, 要不会出现nginx无法启动的错误, 要不会出现403.



iefreer

你可能感兴趣的:(PHP,nginx,yii,techbrood,ufcms)