【问题标题】:Nginx config file isn't locating my Codeigniter/PHP appNginx 配置文件没有找到我的 Codeigniter/PHP 应用程序
【发布时间】: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


【解决方案1】:

上面的一切都与我的 CI 项目相匹配,那么这是我的位置配置:

location ~ \.php$ {
   include /etc/nginx/fastcgi_params;
   fastcgi_pass   127.0.0.1:9000;
   fastcgi_index  index.php;
   fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

不确定是否删除通配符 * 会有所帮助,或者删除 split_info 参数...

【讨论】:

  • -@jpea,谢谢,嗯,我刚刚几乎完全复制了您的 pastebin 代码(我的根目录是 /var/www)。现在我收到 403 Nginx 禁止错误。出于绝望,我然后做了root@ip-xx-xxx-xx-xxx:~# sudo chmod 777 /var/www,但这并没有纠正403。不能说这是更好或更坏,想法?
  • -@jpea,403 特定于 CI 目录/文件,因为从 /var/www 根目录提供 php 文件仍然可以正常工作。呃,真希望我能更好地了解权限......
猜你喜欢
  • 2015-03-16
  • 2023-03-12
  • 2020-12-15
  • 2016-11-16
  • 2021-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-18
相关资源
最近更新 更多