2013-05-15 211 views
0

我是nginx新手。我正在將我的服務器從apache傳輸到nginx,但我在CodeIgniter核心PHP網站上的許多項目都可以正常工作,但CodeIgniter不起作用。Nginx CodeIgniter不能正常工作

我的樣本網址是這樣的:

http://example.com/track/ 

這是重定向到:

http://example.com/track/index.php/sessions/login 

但它返回404未找到。

我的服務器配置是這樣的:像這樣

2013/05/15 10:21:37 [error] 2474#0: *3 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.0.11, server: 192.168.0.80, request: "GET /favicon.ico HTTP/1.1", host: "192.168.0.80" 
2013/05/15 10:21:37 [error] 2474#0: *1 FastCGI sent in stderr: "Unable to open primary script: /usr/share/nginx/html/index.php (No such file or directory)" while reading response header from upstream, client: 192.168.0.11, server: 192.168.0.80, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.0.80" 
2013/05/15 10:22:05 [error] 2474#0: *1 open() "/usr/share/nginx/html/track/index.php/sessions/login" failed (20: Not a directory), client: 192.168.0.11, server: 192.168.0.80, request: "GET /track/index.php/sessions/login HTTP/1.1", host: "192.168.0.80" 
2013/05/15 10:26:46 [error] 2474#0: *5 open() "/usr/share/nginx/html/track/index.php/sessions/login" failed (20: Not a directory), client: 192.168.0.11, server: 192.168.0.80, request: "GET /track/index.php/sessions/login HTTP/1.1", host: "192.168.0.80" 
2013/05/15 10:28:33 [error] 2474#0: *7 open() "/usr/share/nginx/html/track/index.php/sessions/login" failed (20: Not a directory), client: 192.168.0.11, server: 192.168.0.80, request: "GET /track/index.php/sessions/login HTTP/1.1", host: "192.168.0.80" 
2013/05/15 10:29:59 [error] 2497#0: *1 open() "/usr/share/nginx/html/track/index.php/sessions/login" failed (20: Not a directory), client: 192.168.0.11, server: 192.168.0.80, request: "GET /track/index.php/sessions/login HTTP/1.1", host: "192.168.0.80" 

什麼是錯

server { 
    listen  80; 
    server_name 192.168.0.80; 

    location/{ 
     root /usr/share/nginx/html; 
     index index.php index.html index.htm; 
    } 

    #error_page 404    /404.html; 

    # redirect server error pages to the static page /50x.html 
    # 
    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root /usr/share/nginx/html; 
    } 



    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    # 
    location ~ \.php$ { 
     root   /usr/share/nginx/html; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include  fastcgi_params; 
    } 

    # deny access to .htaccess files, if Apache's document root 
    # concurs with nginx's one 
    # 
    location ~ /\.ht { 
     deny all; 
    } 
} 

我的錯誤日誌文件?我在谷歌搜索,但沒有完美的工作。

+0

好的這麼幾個快速問題, 這是一個本地服務器? 並且這個codeIgniter項目運行在你的服務器根目錄的子文件夾中嗎?如果它是這樣,它會改變一些東西 –

+0

這是本地服務器。我正在使用centos在子文件夾上運行&codigniter –

回答

1

看看這個鏈接,應該修復你的重寫問題。
如果您還有其他問題可以提問。
Code igniter for nginx

編輯:
好了,所以有幾種方法可以解決你的情況,但如果你想在同一文件中的nginx的conf編輯,我將描述最接近你的情況

我怎麼覺得你這樣做,現在再嘗試添加該

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

如果路由需要$request_uri附加index.php與否不知道。 我覺得你應該配置笨要知道這個子文件

$config['base_url'] = "192.168.0.80/track" 

這是不是真的這樣做配置最乾淨的方式,我寧願在/etc/hosts添加域名並創建一個新的單獨的服務器在nginx中。

+0

fastcgi.conf文件丟失 –

+0

將這兩行替換爲 'fastcgi_pass unix:/var/run/php5-fpm.sock;' 'include fastcgi_params;' –

+0

Something goes最壞的時候我打電話給這個URL http://192.168.0。80 /跟蹤/重定向到http://192.168.0.80和我的核心PHP項目不工作 –

0

今天早些時候我遇到了類似的問題:代碼點火器URI路由要求定義REQUEST_URI和SCRIPT_NAME變量。許多Nginx/PHP-FPM指南沒有定義SCRIPT_NAME變量,因此最終導致路由失敗。您需要添加一行,看起來像這樣:

fastcgi_param SCRIPT_NAME $fastcgi_script_name; 

,然後你可以在你的的config.php使用REQUEST_URI文件和路由應該工作。