无法使用Phalcon应用程序运行mod_rewrite

时间:2014-10-07 16:47:52

标签: mod-rewrite nginx phalcon

我使用Ubuntu和nginx 1.6.2。我无法运行Phalcon应用程序,因为它使用mod_rewrite规则,但在手册中我找不到nginx规则,只有Apache。这是我的配置:

server {

    listen   80;
    server_name invo;

    index index.php index.html index.htm;
    set $root_path '/home/me/invo/public';
    root $root_path;

    location / {
        try_files $uri $uri/ /index.php;

        # These rules doesn't work
        rewrite ^/$ /public/ break;
        rewrite ^(.*)$ /public/$1 break;

        if (!-e $request_filename){
                rewrite ^(.*)$ /index.php?_url=/$1 break;
        }
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            #fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
    }

    location ~ /\.ht {
        deny all;
    }
}

我评论了三条对我不起作用的规则。我一直打开 http:// invo / cat / index http:// invo / something 我总是看到主页面。

以下是Apache的Phalcon规则:

# /invo/.htaccess
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule  ^$ public/    [L]
    RewriteRule  (.*) public/$1 [L]
</IfModule>

# /invo/public/.htaccess
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

1 个答案:

答案 0 :(得分:1)

这是我的结果工作配置:

server {
    listen   80;
    server_name invo;

    index index.php index.html index.htm;
    set $root_path '/home/me/invo/public';
    root $root_path;

    try_files $uri $uri/ @rewrite;

    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    location ~ \.php {
        fastcgi_index /index.php;

        # The difference from Phalcon manual in this line
        fastcgi_pass unix:/var/run/php5-fpm.sock; 
        include /etc/nginx/fastcgi_params;

        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;

        # Comment out this line too
        #fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
    }

    location ~ /\.ht {
        deny all;
    }
}