0

我是 nginx 新手。我正在将我的服务器从 apache 转移到 nginx,但我在 CodeIgniter 核心 PHP 站点上的许多项目运行良好,但 CodeIgniter 无法运行。

我的示例网址如下:

http://example.com/track/

这是重定向到:

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

但它返回 404 Not Found。

我的服务器配置如下:

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

我的错误日志文件是这样的

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"

怎么了?我在 google 中进行了搜索,但无法正常工作。

4

2 回答 2

1

查看此链接,应该可以解决您的重写问题。
如果您还有其他问题可以提问。
nginx 的代码点火器

编辑:
好的,有几种方法可以解决您的情况,但我将描述最接近您的情况

如果您要在与 nginx conf 相同的文件中进行编辑,就像我认为您现在正在做的那样,请尝试添加这个

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

不确定路由是否需要$request_uri附加index.php。而且我认为您应该配置 CodeIgniter 以了解此子文件夹

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

这并不是真正进行此配置的最干净的方法,我更喜欢在 nginx 中添加一个域名/etc/hosts并创建一个新的单独服务器。

于 2013-05-15T05:06:21.053 回答
0

我今天早些时候遇到了类似的问题:代码点火器 URI 路由要求同时定义 REQUEST_URI 和 SCRIPT_NAME 变量。许多 Nginx/PHP-FPM 指南没有定义 SCRIPT_NAME 变量,因此最终会导致路由失败。您需要添加如下所示的一行:

fastcgi_param  SCRIPT_NAME $fastcgi_script_name;

然后你可以在你的config.php文件中使用REQUEST_URI并且路由应该可以工作。

于 2014-10-02T17:12:48.353 回答