问题描述
Ubuntu 16.04设置rel ="nofollow noreferrer">此和此.
Ubuntu 16.04 setup by referencing this and this.
我可以在http://x.x.x.x/index.php
上看到对CI页面的欢迎,但是当我添加测试控制器并转到http://x.x.x.x/index.php/test
时,我得到404响应.我也不在使用域名,而是在使用IP.
I'm able to see my welcome to CI page on http://x.x.x.x/index.php
, but when I add a test controller and go to http://x.x.x.x/index.php/test
I get a 404 response. I'm also not using a domain but rather just the IP.
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 2;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/;
}
/etc/nginx/sites-available/default:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/codeigniter;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name x.x.x.x;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
/var/www/html/codeigniter/application/config/config.php:
$config['base_url'] = ''; //tried putting http://x.x.x.x
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'REQUEST_URI';
试图创建一个测试控制器:
Tried creating a test controller:
<?php
class Test extends CI_Controller
{
public function index()
{
echo "Hello World!";
}
}
?>
但是它没有加载,并且我收到404响应.
But it doesn't load and I get a 404 response.
有什么想法吗?
推荐答案
更改
try_files $uri $uri/ =404;
收件人:
try_files $uri $uri/ /index.php;
不太确定为什么可以解决此问题,但通过反复试验找到了它: https://www.nginx.com/resources/wiki/start/主题/食谱/codeigniter/
Not really sure why this fixes things, but found it by trial and error referencing:https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/
关于try_files的内容: https://serverfault.com/questions/329592/how-does-try-files-work
Here's a bit on try_files:https://serverfault.com/questions/329592/how-does-try-files-work
这篇关于CodeIgniter路由在Nginx下不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!