[英]Codeigniter Nginx Controller Functions Returning 404
我当前在服务器上运行nginx和codeigniter。 我可以访问基本功能,例如
sample.dev/samplecontroller
但是当我尝试在该控制器中指定功能时,例如
sample.dev/控制器/功能
我收到404错误
项目sample.dev的我的站点可用文件如下:
server {
listen 80 ;
listen [::]:80;
root /var/www/html/sample_ci;
# Add index.php to the list if you are using PHP
index index.html index.php index.htm index.nginx-debian.html;
server_name sample.dev;
location / {
# URLs to attempt, including pretty ones.
try_files $uri $uri/ /index.php?$query_string;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# include snippets/fastcgi-php.conf;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
我对该项目的.htaccess文件也如下:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sample_ci
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /HCMP/index.php/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
而且我已经将config.php文件变量配置如下:
$config['base_url'] = 'http://sample.dev/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
尽管按照我在nginx官方网站和我在此处找到的其他帖子上的所有步骤进行操作,但上述配置无法正常工作。 我有什么做错或应该做的吗?
您不能在nginx上使用.htaccess文件...这些文件主要用于Apache。 因此,您的重写未被使用,并且您将始终得到404。
您需要知道的是:
https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/#
http://www.farinspace.com/codeigniter-nginx-rewrite-rules/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.