我的服务器是Nginx。我的网站是在Codeigniter上制作的
server {
listen 80;
server_name idealcloud.idealcontrol.cl;
root /var/www/idealcontrol_cloud/idealcloud/idealcloud_ox_cer/sys/;
index index.php home.php login.php;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
include fastcgi.conf;
}
}
但是它只显示空白页,nginx日志和codeigniter日志中没有错误。有人知道吗?
答案 0 :(得分:0)
遗憾的是,codeigniter在Nginx上不能像在Apache上那样无缝地工作,因此您需要在nginx.conf
文件上进行大量配置才能获得可正常运行的Codeigniter站点。
我不记得确切的最低配置,因此,我将为您提供一些我现在正在研究的摘录的摘录。自行替换域,路径和用户
Nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 65535;
multi_accept on;
}
http {
charset utf-8;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
log_not_found off;
types_hash_max_size 2048;
client_max_body_size 16M;
fastcgi_read_timeout 300;
# MIME
include mime.types;
default_type application/octet-stream;
# logging
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;
# load configs
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name example.com;
set $base /home/path/to/wwwdir;
root $base;
# this is important so that nginx and CI can work together without htaccess
# index.php
index index.php;
# index.php fallback
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# this is important so that nginx and CI can work together without htaccess
# handle .php
location ~ \.php$ {
try_files $uri =404;
# fastcgi
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_ADMIN_VALUE open_basedir=$base/:/usr/lib/php/:/tmp/;
fastcgi_intercept_errors off;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
# fastcgi_read_timeout 300;
# default fastcgi_params
include fastcgi_params;
}
# security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always;
# . files
location ~ /\. {
deny all;
}
# assets, media
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
expires 7d;
access_log off;
}
# svg, fonts
location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff|woff2)$ {
add_header Access-Control-Allow-Origin "*";
expires 7d;
access_log off;
}
# gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;
}
# subdomains redirect
server {
listen 80;
listen [::]:80;
server_name *.example.com;
return 301 https://example.com$request_uri;
}
}
上面的内容绝不完整(缺少HTTPS配置和其他内容),但足以让您入门