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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)