![](/img/trans.png)
[英]How can I configure Codeigniter in NGINX server? .htaccess not working
[英]How do I configure nginx and 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;
}
}
}
其實我得到了這個工作。 不確定如何,但我認為這是文件權限設置不正確或其他原因。
編輯:對於那些想知道的人,我似乎安裝了舊版本的 PHP。 恢復到舊的類構造函數解決了這個問題。 達尼特。
我有完全相同的問題(Codeigniter 給出空白頁面,錯誤頁面和 php 正在工作),我發現問題來自 mysql db 驅動程序,它應該更改為 mysqli 驅動程序。
所以我們只需要更改 config/database.php 中的數據庫驅動程序
$db['default']['dbdriver'] = 'mysqli';
這是由於 mysql 驅動程序在新版本的 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/
server ip: 10.0.0.10 port: 8085 project name is 'test' 請根據需要修改!
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'
重要提示:不要對服務器 URL 使用“localhost”!!!!!!
請取消注釋:# 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
這是一個解決方案。
另外,我不得不更改$config['uri_protocol'] = “DOCUMENT_URI”;
使其工作。
更新:修復了網絡存檔中的 404 網址。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.