2014-10-07 39 views
0

我使用Ubuntu和nginx 1.6.2。我無法運行Phalcon應用程序,因爲它使用mod_rewrite規則,但在手冊中我找不到nginx規則,只能使用Apache。這裏是我的配置:無法使用Phalcon應用程序運行mod_rewrite

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/indexhttp:// invo/something我總是看到主頁面。

這裏的爾康規則阿帕奇:

# /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

這裏是我的結果工作配置:

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; 
    } 
}