2

我有一个在 NGINX 上运行的股票 CI 应用程序。没有重写(我尝试了 16 个小时,无法让它工作。它要么是 500、404、403,要么是未指定输入文件),php 文件被传递给 php-fpm。

这是我在可用站点下的默认文件(Ubuntu 12.04,在 CentOS 上尝试了一切,但没有任何效果):

server {

        listen   80;    

        root /usr/share/nginx/www/;
        index index.php index.html index.htm;
        server_name fish-in-a-bowl.net;

        location / {
                try_files $uri $uri/ /index.html;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www/cloud;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
                #fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

        }
}

并且config.php

$config['base_url'] = 'http://fish-in-a-bowl.net/zz/';

$config['index_page'] = 'index.php';

//$config['index_page'] = '';

//$config['uri_protocol']   = 'PATH_INFO';
//$config['uri_protocol']   = 'QUERY_STRING';
//$config['uri_protocol']   = 'REQUEST_URI';
//$config['uri_protocol']   = 'DOCUMENT_URI';
//$config['uri_protocol']   = 'ORIG_PATH_INFO';

$config['uri_protocol'] = 'AUTO';

我已经尝试了所有可用的选项,但没有一个有效。这个节点在 Digital Ocean 上,他们有使用 Apache 而不是 NGINX 设置 CI 的教程。

默认控制器有效,但是当通过http://fish-in-a-bowl.net/zz/index.php/welcome访问时,我得到No input file specified.

帮助?这太奇怪了。

截图 >

在此处输入图像描述

4

6 回答 6

1

在您的 nginx 服务配置更改中:

location / {
    try_files $uri $uri/ /index.html;
}

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

在您的 CI config.php 集中:

$config['index_page'] = '';
$config['uri_protocol'] = "REQUEST_URI";
于 2014-02-27T12:54:46.383 回答
1

在你的 nginx 设置中试试这个

# enforce NO www
if ($host ~* ^www\.(.*))
{
    set $host_without_www $1;
    rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}

# canonicalize codeigniter url end points
# if your default controller is something other than "welcome" you should change the following
if ($request_uri ~* ^(/welcome(/index)?|/index(.php)?)/?$)
{
    rewrite ^(.*)$ / permanent;
}

# removes trailing "index" from all controllers
if ($request_uri ~* index/?$)
{
    rewrite ^/(.*)/index/?$ /$1 permanent;
}

# removes trailing slashes (prevents SEO duplicate content issues)
if (!-d $request_filename)
{
    rewrite ^/(.+)/$ /$1 permanent;
}

# removes access to "system" folder, also allows a "System.php" controller
if ($request_uri ~* ^/system)
{
    rewrite ^/(.*)$ /index.php?/$1 last;
    break;
}

# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename)
{
    rewrite ^/(.*)$ /index.php?/$1 last;
    break;
}
于 2014-04-02T06:09:13.200 回答
0

只需为 CI 添加一个新的位置块

location ~ /zz(?<myuri>.*) {
    root /path/to/root/zz;
    try_files $myuri $myuri/ /index.php$myuri$is_args$query_string;
}

那应该做这一切,测试它并告诉我它是如何进行的。

于 2013-08-02T04:12:40.970 回答
0

尝试以下,对我来说是一个梦想。不要忘记更改 fastcgi_pass,并在尝试之前备份当前配置。

server
{
    listen   Server IP:80;
    server_name domain.name;

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

    root /path/to/www;

    index index.php index.html index.htm;

    # enforce www (exclude certain subdomains)
#   if ($host !~* ^(www|subdomain))
#   {
#       rewrite ^/(.*)$ $scheme://www.$host/$1 permanent;
#   }

    # enforce NO www
    if ($host ~* ^www\.(.*))
    {
        set $host_without_www $1;
        rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
    }

    # canonicalize codeigniter url end points
    # if your default controller is something other than "welcome" you should change the following
    if ($request_uri ~* ^(/welcome(/index)?|/index(.php)?)/?$)
    {
        rewrite ^(.*)$ / permanent;
    }

    # removes trailing "index" from all controllers
    if ($request_uri ~* index/?$)
    {
        rewrite ^/(.*)/index/?$ /$1 permanent;
    }

    # removes trailing slashes (prevents SEO duplicate content issues)
    if (!-d $request_filename)
    {
        rewrite ^/(.+)/$ /$1 permanent;
    }

    # removes access to "system" folder, also allows a "System.php" controller
    if ($request_uri ~* ^/system)
    {
        rewrite ^/(.*)$ /index.php?/$1 last;
        break;
    }

    # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
    if (!-e $request_filename)
    {
        rewrite ^/(.*)$ /index.php?/$1 last;
        break;
    }

    # catch all
    error_page 404 /index.php;

    # use fastcgi for all php files
    location ~ \.php$
    {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /path/to/www/$fastcgi_script_name;
        include fastcgi_params;
    }

    # deny access to apache .htaccess files
    location ~ /\.ht
    {
        deny all;
    }
}
于 2013-08-01T21:48:33.313 回答
0
location /atri/ {
alias  /var/www/html/atri/;
try_files $uri $uri/ /atri/index.php;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index   index.php;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    include /etc/nginx/fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME $request_filename;
}

}

于 2017-05-22T10:14:12.763 回答
0

尝试这个

location ~ \.php($|/.+) { 

    fastcgi_pass 127.0.0.1:9000;

    fastcgi_split_path_info         ^(.+\.php)(/.*)$;
    fastcgi_param   SCRIPT_FILENAME $request_filename;
    include fastcgi_params;
}
于 2016-08-17T05:23:03.297 回答