Php 由nginx或apache提供服务的Yii站点只提供主页
编辑一个:我还用apache在Windows7上测试了这一点,同样的情况也发生了。这意味着问题主要在于将所有页面路由到主页 编辑两个:根据#yii IRC频道的建议,我将.htaccess文件的内容替换为一个工作项目中简化的内容。然而,这并没有改变这个问题 编辑三:我的代码做了一些修改,现在可以正常工作了。下面的答案 我一直在尝试导入一个用Yii框架编写的站点,我已经将该框架导入了我的工作站。我遇到了一个问题,试图加载任何页面只会直接指向主页。这意味着所有请求基本上都被路由,就像我加载了根请求一样。访问日志或错误日志中没有弹出错误;在nginx的访问日志中,请求如下所示,其中“example”是“localhost”、“127.0.0.1”或服务器的IP地址:Php 由nginx或apache提供服务的Yii站点只提供主页,php,yii,nginx,Php,Yii,Nginx,编辑一个:我还用apache在Windows7上测试了这一点,同样的情况也发生了。这意味着问题主要在于将所有页面路由到主页 编辑两个:根据#yii IRC频道的建议,我将.htaccess文件的内容替换为一个工作项目中简化的内容。然而,这并没有改变这个问题 编辑三:我的代码做了一些修改,现在可以正常工作了。下面的答案 我一直在尝试导入一个用Yii框架编写的站点,我已经将该框架导入了我的工作站。我遇到了一个问题,试图加载任何页面只会直接指向主页。这意味着所有请求基本上都被路由,就像我加载了根请求一
Accessing root ( http://example/ ):
127.0.0.1 - - [08/May/2013:13:05:28 -0700]
"GET / HTTP/1.1" 200 8436 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0"
Accessing login ( http://example/site/login ):
127.0.0.1 - - [08/May/2013:13:07:01 -0700]
"GET /site/login HTTP/1.1" 200 8427 "http://example/" "Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0"
Accessing the same controller by http://example/index.php?r=site/login:
127.0.0.1 - - [08/May/2013:14:40:45 -0700]
"GET /index.php?r=site/login HTTP/1.1" 200 8419 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0"
考虑到我已经设置了另外两个Yii项目,它们运行良好,并且使用了类似于下面我也将粘贴的服务器配置,我认为这可能是应用程序本身工作中我还不热衷的东西。如果有人对我从其他网站导入的工作项目中可以分享、尝试或比较的其他内容有任何建议,我将不胜感激:)
编辑:切换到更接近我实际使用的配置。考虑到该项目在Windows上的Apache中运行时也存在同样的问题,这可能与此无关。
server {
server_name localhost;
listen 80;
keepalive_timeout 70;
root /usr/www/[project name omitted]/public_html;
client_max_body_size 4M;
client_body_buffer_size 4M;
client_header_buffer_size 4M;
location / {
try_files $uri $uri/ /index.php?$args;
autoindex on;
}
location ^~ /data/ {
expires 30d;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
#Disable logging for favicon
location = /favicon.ico {
log_not_found off;
access_log off;
}
#Disable logging for robots.txt
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /themes/\w+/views {
deny all;
access_log off;
log_not_found off;
}
# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
try_files $uri =404;
#fastcgi_intercept_errors on;
#fastcgi_connect_timeout 20;
fastcgi_send_timeout 20;
fastcgi_read_timeout 600; # For xdebug to work alright
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}
您应该从
位置/
配置中删除此行:
index index.html $yii_bootstrap;
基本上,您告诉Nginx它应该始终使用
$yii_bootstrap
作为索引文件。因此,try_files一行从未使用过。我可以看到两件事。通常,对于Yii应用程序,我的位置块设置如下。不是index.php文件前面的“~”和正斜杠。我还将把索引选项移到该位置块之外的服务器根块中。因此,您的位置块应该如下所示
location ~ / {
try_files $uri $uri/ /index.php?$args;
}
第二件事与php位置块有关。除非运行多个php文件,否则只需指定对index.php的访问权限,而不允许访问任何面向web的php文件
location ~ index.php$ {
不过,此位置块应该适合您:
location ~ index.php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /path/to/yii/app$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors off;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
在联系了这个项目的原始开发人员之后,我已经把一切都整理好了,他已经通知我需要做一些更改。详情如下:
- 正在更新如下所示的代码实例:
session_start(); $_SESSION['allowdownload'] = true; session_write_close();
- 为此:
$session=new CHttpSession; $session->open(); $session['allowdownload'] = true; $session->close();
- 以及将urlManager数组中protected/config/main.php中“showScriptName”的设置更改为“true”而不是“false”。我希望这能在某个时候帮助其他人