【发布时间】:2012-07-31 07:19:37
【问题描述】:
我不知道如何让 Nginx 配置文件找到我的 Codeigniter 应用程序。在这个服务器上服务 PHP 不是问题 b/c 如果我把一个 php 文件放在我的根目录中,我可以echo "hello world";。
这是我的 Nginx 配置文件,它几乎是来自 this tutorial 的逐字记录。请注意,我已经操作了许多这些参数,但没有一个有效果,所以我想知道是否需要超越这个文件才能让它工作?:
server {
listen 80;
server_name www.mysite.com mysite.com;
root /var/www;
index index.html index.php index.htm;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
try_files $uri $uri/ /index.php;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
我一直认为这是一个简单的路径问题 b/c Codeigniter 的路由结构有些混乱,但我的配置看不到问题。想法?
【问题讨论】:
-
您是否修改了 Codeigniter 的配置以使用 Nginx?你的 Nginx 配置看起来不错。
-
@AzizAG 我的 Codeigniter 2.1.2 配置似乎是标准配置。我有一个名为“main”的默认控制器,通过 config/config.php 在 URL 中删除了“index.php”。我的系统、应用程序文件夹和 CI index.php 文件位于根目录中。我有一个带有通用 .htaccess 文件的 Apache 服务器,它可以很好地为我的 CI 应用程序提供服务,所以我不确定问题是什么。
-
我会在没有删除 index.php 的情况下试一试,看看你是否可以让它工作。这至少可以缩小问题的范围。
-
@jpea,你的意思是在 config/config.php 文件中恢复这个?:
$config['index_page'] = 'index.php';我刚试过这个,然后去了 mysite.com/index.php/main 但仍然没有运气. -
是的,这就是我的建议。我在下面发布了我的配置作为答案。可能有用吗?
标签: php codeigniter nginx app-config server-configuration