2013-08-01 25 views
2

我有一个在NGINX上运行的股票CI应用程序。没有重写(我尝试了16个小时,并没有得到它的工作,它是500,404,403或输入文件没有指定),PHP文件被传递给php-fpm。CodeIgniter,NGINX里面的文件夹不工作

这里提供的网站在我的默认文件(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设置CI而不是NGINX的教程。

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

帮助?这太奇怪了。

SCREENSHOT>

enter image description here

+0

尝试:fastcgi_param SCRIPT_FILENAME /路径/到/ WWW/$ fastcgi_script_name; –

+0

我试过了,同样的错误没有指定输入文件。在Ubuntu 12.04上它是/ usr/share/nginx/www/ –

+0

从技术上讲,它是你想要的任何东西,你是否在我的答案中尝试过配置? –

回答

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; 
    } 
} 
0

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

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

这应该做到这一切,测试,并告诉我是怎么回事。

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"; 
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; 
} 
+0

你可能会为你的答案增加一点解释为什么这应该是可行的解决方案;-) – Samoth

+0

你可以阅读fuul解释在这里http://www.farinspace.com/codeigniter-nginx-rewrite-rules/ – pythondjango

+0

它为我工作!我正在维护内部应用程序,其中一个是CodeIgnitor,它可以在/ cma上访问,我尝试了一切,但它们不起作用!
即使官方网站的说明没有,但你的工作。
其中一个主要的重要问题是/ cma正在接收404 /未找到!

0

试试这个

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

    fastcgi_pass 127.0.0.1:9000; 

    fastcgi_split_path_info   ^(.+\.php)(/.*)$; 
    fastcgi_param SCRIPT_FILENAME $request_filename; 
    include fastcgi_params; 
} 
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; 
} 

}

相关问题