編輯之一:我也用apache在Windows 7上測試了這個,並且發生了完全相同的事情。這意味着問題主要在於將所有頁面路由到主頁。由nginx或apache服務的Yii站點只服務主頁
編輯二:根據#yii IRC頻道的建議,我用工程項目中的一個非常簡單的內容替換了.htaccess文件的內容。但是,這並沒有導致問題的任何改變。
編輯三:我已經得到了這個工作很好,現在有一些更改我的代碼。下面的答案
我一直在嘗試導入一個使用Yii框架編寫的網站,這個網站已經導入我的工作站。我遇到了一個問題,試圖加載任何頁面只會直接進入主頁面。這意味着所有請求都基本上按照加載根請求的方式進行路由。訪問日誌或錯誤日誌中不會彈出任何錯誤;請求看起來像nginx的的訪問日誌,其中「例如,」或者是「localhost」的,「127.0.0.1」,或服務器的IP地址如下:
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"
考慮到我有2其他的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;
}
}
其實我已經走了,在嘗試別的東西了比你看到的前介於編輯配置文件(這正是我所複製並從什麼警予文檔本身具有了粘貼爲:https:/ /code.google.com/p/yii/source/browse/trunk/docs/guide/quickstart.apache-nginx-config.txt)。編輯後的配置文件包含更接近你的建議的東西,但完全沒有辦法解決我的問題。我會用apache來試試這個 - 我仍然懷疑這是一個nginx問題,但我可能是錯的。還是)感謝你的建議。 – 2013-05-09 13:01:57