我在家用电脑上运行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;
}
}
}
答案 0 :(得分:1)
实际上我有这个工作。不确定如何,但我认为文件权限设置不正确或其他。
编辑: 对于那些想知道的人,我似乎安装了旧版本的PHP。恢复旧类构造函数可以解决问题。 Darnit。
答案 1 :(得分:0)
我有完全相同的问题(Codeigniter给出空白页面,错误页面和php正在工作),我发现问题来自mysql db驱动程序,应该更改为mysqli驱动程序。
所以我们只需要在config / database.php中更改db驱动程序
$db['default']['dbdriver'] = 'mysqli';
这是因为在新版本的php中不推荐使用mysql驱动程序。
答案 2 :(得分:0)
CodeIgniter4如何在RasperyPi Debian 10.4上设置NGINX服务器块(虚拟主机)
我正在使用RasperyPi-4作为Web开发服务器,并在其上运行不同的项目。 Visual Studio Code允许通过Remote-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/
服务器ip:10.0.0.10 端口:8085 项目名称为“测试” 请根据您的需要进行修改!
cd /var/www/html
composer create-project codeigniter4/appstarter test
上面的命令将创建一个'test'文件夹/ var / www / html / test
sudo nano /var/www/html/test/env
app.baseURL = 'http://10.0.0.10:8085'
重要提示:请勿将“ localhost”用作服务器URL !!!!
请取消注释: #CI_ENVIRONMENT =生产 并修改: CI_ENVIRONMENT =开发
将文件另存为“ .env”以隐藏文件
cd /etc/nginx/sites-available
touch test
sudo nano test
将其粘贴到文件中,然后根据需要进行修改后保存:
server {
listen 8085;
listen [::]:8085;
server_name test;
root /var/www/html/test/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm:
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
# With php-cgi:
# fastcgi_pass 127.0.0.1:9000;
}
error_page 404 /index.php;
# deny access to hidden files such as .htaccess
location ~ /\. {
deny all;
}
}
保存文件后,创建指向启用站点的符号链接:
cd /etc/nginx/sites-enabled
sudo ln -s /etc/nginx/sites-available/test /etc/nginx/sites-enabled/test
chown -v -R pi:www-data /var/www/html/test
sudo chmod -v -R 775 /var/www/html/test
sudo service nginx start
http://10.0.0.10:8085
答案 3 :(得分:-1)
这是一个解决方案。
另外,我必须更改$config['uri_protocol'] = “DOCUMENT_URI”;
才能使其正常工作。
更新:修复了网络存档中的404网址。