CodeIgniter не работает под Nginx

Настройка Ubuntu 16.04 по ссылке этот а также этот.

Я могу видеть мою страницу приветствия CI на http://x.x.x.x/index.php, но когда я добавляю тестовый контроллер и http://x.x.x.x/index.php/test Я получаю ответ 404. Я также не использую домен, а просто IP.

/etc/nginx/nginx.conf:

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

/ И т.д. / Nginx / сайты-доступные / по умолчанию:

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';

Попробовал создать тестовый контроллер:

<?php
class Test extends CI_Controller
{
public function index()
{
echo "Hello World!";
}
}
?>

Но он не загружается, и я получаю ответ 404.

Есть идеи?

2

Решение

изменения

try_files $uri $uri/ =404;

чтобы:

try_files $uri $uri/ /index.php;

Не совсем уверен, почему это все исправляет, но нашел его методом проб и ошибок:
https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/

Вот немного о try_files:
https://serverfault.com/questions/329592/how-does-try-files-work

2

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector