nginx重写锂电池框架的规则

我一直在试图让Nginx运行lithium没有成功。 lithium的目录结构就是这样

 lithium |-> app libraries .htaccess |-> webroot .htacess --other directories |-> index.php .htaccess --other files 

我将lithium文件夹复制到我的/var/www/ 。 锂的path是/var/www/lithium/

现在我在我的nginx.conf这种方式设置重写规则

 server { listen 80; server_name localhost; root /var/www/; location /lithium { rewrite ^/$ /app/webroot/ break; rewrite ^(.*)$ /app/webroot/$1 break; } location /lithium/app { rewrite ^/$ /webroot/ break; rewrite ^(.*)$ /webroot/$1 break; } location /lithium/app/webroot { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?url=$1 break; } } ...then my php and other configurations 

但是nginx总是抛出一个404错误。 为什么会这样呢?

我也试过这个

 server { listen 80; server_name localhost; root /var/www/; location /lithium { if (!-e $request_filename) { rewrite ^/lithium/(.+)$ /lithium/app/webroot/$1 last; break; } } location /lithium/app/webroot { if (!-e $request_filename) { rewrite ^/lithium/app/webroot/(.+)$ /lithium/app/webroot/index.php?url=$1 last; break; } } ...then my php and other configurations 

但是又有一个404错误。

编辑

build议我把我的服务器的根改为/var/www/lithium/app/webroot所以我的nginx conf看起来像这样

 server { listen 80; server_name localhost; root /var/www/lithium/app/webroot; access_log /var/log/lithium/access.log; error_log /var/log/lithium/error.log warn; index index.php index.html; try_files $uri $uri/ /index.php?$args; location ~ \.php$ { .. ... ...... } 

现在我可以看到锂的家,但是当我去锂的testing仪表板这是http://localhost/test它再次显示锂的家庭,而不是testing仪表板。当我使用Apache和去http://localhost/test它向我显示test dashboard 。 所以nginx的重写规则仍然不完全正确。更多的,如果我指向lithium's webroot我不能访问其他目录在我的/var/www/

EDITED AGIAN

这是我完整的服务器块

 server { server_name lithium; root /var/www/lithium/app/webroot; access_log /var/log/nginx/lith.access.log; error_log /var/log/nginx/lith.error.log; listen 127.0.0.2:80; rewrite_log on; # rewrite rules for lithium location / { index index.php index.html; try_files $uri $uri/ /index.php?url=$uri&$args; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #include /etc/nginx/fastcgi_params; fastcgi_param SERVER_NAME $host; } location ~ /\.ht { deny all; } } 

我正在使用PHP 5.4.3。 作为php-fpm。 我尝试在锂官方网站上提到的东西,但是我没有得到这个线

 cp -f sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 

哪个位置是sapi指的? 有任何想法吗?

使用root /var/www/lithium/app/webroot指向webroot会更简单。

或者你可以做到以下几点。

 root /var/www 

那么使用try_files而不是丑陋的:

 index index.php index.html; location ~ \.php$ { ... } location lithium/app/webroot/ { try_files $uri $uri/ /lithium/app/webroot/index.php?$args; } location /lithium/app/ { rewrite ^/lithium/app/(.*)$ /lithium/app/webroot/$1; } location /lithium/ { rewrite ^/lithium/(.*)$ /lithium/app/webroot/$1; } location / { rewrite ^(.*)$ /lithium/app/webroot/$1; } 

不要忘记保护其他目录。

 try_files $uri $uri/ /index.php?$args; 

您没有将URI传递给Lithium – 您正在附加查询string,该string为空。 您可能需要以下内容:

 try_files $uri $uri/ /index.php?url=$uri&$args; 

假设锂电池预计将被调用index.php?uri=/test (这是你原来的configuration所暗示的)。

编辑 : 锂维基build议顶部try_files行,这意味着它检查FastCGIvariables,以确定要服务的URL。

我认为你没有设定正确的path。 尝试运行一个基本的nginxconfiguration: http : //lithify.me/docs/manual/configuration/servers/nginx.wiki

打开PHP错误也是有帮助的。 像设置锂库path的configuration错误不明显,除非你有PHP错误打开。

 #include /etc/nginx/fastcgi_params; 

您不包括设置传递给PHP的大部分FastCGIvariables的configuration文件,因此Lithium可能无法确定要请求的URL。 取消注释此行并将其移动到SCRIPT_FILENAME行的上方,以使您的块如下所示:

 location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SERVER_NAME $host; }