我有一个在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.
帮助?这很奇怪。
SCREENSHOT>
答案 0 :(得分: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 :(得分: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;
}
答案 2 :(得分: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;
}
}
答案 3 :(得分:0)
只需为CI添加新的位置块
location ~ /zz(?<myuri>.*) {
root /path/to/root/zz;
try_files $myuri $myuri/ /index.php$myuri$is_args$query_string;
}
应该做到这一切,测试它并告诉我它是怎么回事。
答案 4 :(得分:0)
试试这个
location ~ \.php($|/.+) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
答案 5 :(得分: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;
}
}