如何配置 nginx 和 CodeIgniter?
我在我的家用计算机上运行 nginx 进行开发。我还将其链接到 DynDNS,这样我就可以更轻松地向同事展示进度。我似乎无法让 nginx 正确重写 CodeIgniter。我将 CodeIgniters uri_protocol 设置为 REQUEST_URI。
所有应该显示内容的页面都显示为完全空白。如果我 phpinfo();死();在 Codeigniter 的 index.php 文件中,它按预期工作,我得到了 phpinfo。
此外,应该给出 404 的页面也会给出正确的 CodeIgniter 404 错误。
这是我到目前为止所拥有的。
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
#gzip on;
#gzip_disable "MSIE [1-6]\.(?!.*SV1)";
root /home/zack/Development/public_html;
include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
server {
listen 80;
server_name zackhovatter.dyndns.info;
index index.php;
root /home/zack/Development/public_html;
location /codeigniter/ {
if (!-e $request_filename) {
rewrite ^/codeigniter/(.*)$ /codeigniter/index.php/$1 last;
}
}
#this is for the index.php in the root folder
location /index.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/zack/Development/public_html/index.php;
include fastcgi_params;
}
location /codeigniter/index.php {
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/zack/Development/public_html/codeigniter/index.php;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param PATH_INFO $document_uri;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass 127.0.0.1:9000;
}
}
}
I'm running nginx on my home computer for development. I also have it linked to DynDNS so I can show progress to my co-worker a bit easier. I can't seem to get nginx to rewrite to CodeIgniter properly. I have CodeIgniters uri_protocol set to REQUEST_URI.
All pages that should be showing up wtih content show up completely blank. If I phpinfo(); die(); in the index.php file of Codeigniter, it works as expected and I get the phpinfo.
Also, pages that should give a 404 give a proper CodeIgniter 404 error.
Here's what I have so far.
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
#gzip on;
#gzip_disable "MSIE [1-6]\.(?!.*SV1)";
root /home/zack/Development/public_html;
include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
server {
listen 80;
server_name zackhovatter.dyndns.info;
index index.php;
root /home/zack/Development/public_html;
location /codeigniter/ {
if (!-e $request_filename) {
rewrite ^/codeigniter/(.*)$ /codeigniter/index.php/$1 last;
}
}
#this is for the index.php in the root folder
location /index.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/zack/Development/public_html/index.php;
include fastcgi_params;
}
location /codeigniter/index.php {
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/zack/Development/public_html/codeigniter/index.php;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param PATH_INFO $document_uri;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass 127.0.0.1:9000;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
事实上我得到了这个工作。不知道如何,但我认为这是文件权限设置不正确或其他原因。
编辑:
对于那些想知道的人,我似乎安装了旧版本的 PHP。恢复到旧的类构造函数解决了这个问题。达尼特。
Actually I got this working. Not sure how, but I think it was file permissions being set incorrectly or something.
Edit:
For those who are wondering, I had an older version of PHP installed it seems. Reverting back to old class constructors fixed the issue. Darnit.
我有完全相同的问题(Codeigniter 给出空白页面,错误页面和 php 正在工作),我发现问题来自 mysql db 驱动程序,应该更改为 mysqli driver 。
所以我们只需要更改 config/database.php 中的 db 驱动程序
,这是因为新版本的 php 中不推荐使用 mysql 驱动程序。
I have exactly the same problem (Codeigniter gives blank pages and the error pages and php are working) and i found that the problem was from the mysql db driver which should be changed to mysqli driver .
So just we need to change the db driver in config/database.php
And this is due that the mysql driver is deprecated in the new versions of php.
CodeIgniter4 如何在 RasperyPi Debian 10.4 上设置 NGINX 服务器块(虚拟主机)
我使用 RasperyPi-4 作为 Web 开发服务器,并在其上运行不同的项目。
Visual Studio Code 可以非常轻松地通过远程 SSH 扩展编辑文件。
在 NGINX 上设置 CI4 让您有机会在同一服务器上运行不同的项目。
因为我花了几天时间才运行此配置,所以我将为您提供快速参考指南,以便您快速轻松地进行设置。
如果您还没有安装 NGINX 和 Composer,请看这里:
http://nginx.org/en/docs/beginners_guide.html
https://codeigniter4.github.io/userguide/installation/installing_composer.html
https://getcomposer.org/download/
通过 Composer服务器 ip: 10.0.0.10
端口:8085
项目名称是“测试”
请根据您的需求进行修改!
上面的命令将创建一个“test”文件夹 /var/www/html/test
重要提示:不要使用“localhost”作为服务器 URL!!!!
请取消注释:
# CI_ENVIRONMENT = 生产
并修改:
CI_ENVIRONMENT =development
将文件另存为“.env”以隐藏文件
将其粘贴到文件中,并根据您的要求进行修改后保存:
保存文件后,创建指向已启用站点的符号链接:
CodeIgniter4 How To Setup NGINX Server Blocks (Virtual Hosts) on RasperyPi Debian 10.4
I am using a RasperyPi-4 as web developing server with different projects running on it.
Visual Studio Code enables editing files via Remote-SSH extension very easily.
Setting up CI4 on NGINX gives you the opportunity to run different projects on the same server.
Because it took me some days to get this configuration running I will give you a quick reference guide to setup quick and easy.
If you have not installed NGINX and composer yet please have a look here:
http://nginx.org/en/docs/beginners_guide.html
https://codeigniter4.github.io/userguide/installation/installing_composer.html
https://getcomposer.org/download/
server ip: 10.0.0.10
port: 8085
project name is 'test'
Please modify to your needs!
the command above will create a 'test' folder /var/www/html/test
Important: Do NOT use 'localhost' for the server URL!!!!!
please uncomment:
# CI_ENVIRONMENT = production
and modify:
CI_ENVIRONMENT = development
Save the file as '.env' to hide the file
Paste this into the file and save after modifying to your requirements:
After saving the file create a symbolic link to sites-enabled:
这是一个解决方案。
https:/ /web.archive.org/web/20120504010725/http://hiteshjoshi.com/linux/secure-nginx-and-codeigniter-configuration.html
另外,我必须更改
$config['uri_protocol '] = “DOCUMENT_URI”;
使其正常工作。更新:修复了网络存档中的 404 url。
Here is a solution.
https://web.archive.org/web/20120504010725/http://hiteshjoshi.com/linux/secure-nginx-and-codeigniter-configuration.html
Also, I had to change
$config['uri_protocol'] = “DOCUMENT_URI”;
to make it work.UPDATE: Fixed the 404 url from web archive.