codeigniter不能在nginx中运行(在localhost上运行),linux mint

时间:2016-03-14 09:46:12

标签: php linux codeigniter nginx url-rewriting

我在我的linux mint系统上安装了LEMP。 nginx配置为使用php5-fpm套接字。 当我在我的系统中运行codeigniter index.php(link:localhost / ci / index.php)出现时,但是当我尝试打开任何控制器时,说博客(link localhost / ci / index.php / blog)nginx给出 404错误消息。

以下是我的nginx配置放在文件/ etc / nginx / sites-avaliable / default

server {
listen 127.0.0.1:80;
listen [::]:80 default_server ipv6only=on;
root /home/scoders/Workspace/public_html;
index index.html index.htm index.php;
autoindex on;

server_name localhost;

location / {
    try_files $uri $uri/ /index.php?$args;
}

# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/scoders/Workspace/public_html/ci/index.php;
    #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

}

nginx.conf的内容如下:

user scoders;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
}
http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";

    xml+rss text/javascript;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    include /etc/nginx/sites-enabled/*.conf;
    server_names_hash_bucket_size 64;
}

我的日志出现以下错误:

    2016/03/14 14:38:38 [error] 23239#0: *1 FastCGI sent in stderr: 
"Primary script unknown" while reading response header from upstream, 
client: 127.0.0.1, server: localhost, request: "GET /ci/index.php/ci 
HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "localhost"

我试过这些链接但没有运气:

Codeigniter | NGINX

CodeIgniter NGINX Rewrite Rules

1 个答案:

答案 0 :(得分:1)

/home/scoders/Workspace/public_html/ci/index.php由于某种原因无法访问,或SCRIPT_FILENAME

中正在覆盖include fastcgi_params;

作为一般规则,您应先include,然后fastcgi_param

例如:

location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    include fastcgi_params;
    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

此外,如果您的默认URI为/ci/index.php而非/index.php,请将您的location /更改为:

location / {
    try_files $uri $uri/ /ci/index.php?$args;
}