doulai8405 2013-05-15 05:03
浏览 168

Nginx CodeIgniter无法正常工作

I am new to nginx. I am transfering my server from apache to nginx but my many projects on the CodeIgniter core PHP sites working perfectly but the CodeIgniter is not work.

My sample url like this:

http://example.com/track/

this is redirect to:

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

but it returns 404 Not Found.

my server configure like this:

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

my error log file like this

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"

What's wrong? I did a search in google but not working perfectly.

  • 写回答

2条回答 默认 最新

  • dongwuqi4243 2013-05-15 05:06
    关注

    Check out this link, should fix your rewriting issues.
    If you have further questions you can ask.
    Code igniter for nginx

    Edit:
    Ok so there's several ways to fix your case, but I'll describe the closest to your case

    If you're going to edit in the same file as nginx conf as how I think you're doing right now then try adding this

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

    Not sure if the routing needs $request_uri appended to index.php or not. And i think you should configure CodeIgniter to be aware of this sub folder

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

    This isn't really the cleanest way to do this configuration, I'd prefer adding a domain name in the /etc/hosts and create a new separate server in nginx.

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序