gpt4 book ai didi

php - CodeIgniter 路由在 Nginx 下不工作

转载 作者:行者123 更新时间:2023-12-02 22:19:15 25 4
gpt4 key购买 nike

通过引用 this 设置 Ubuntu 16.04和 this .

我可以在 http://x.x.x.x/index.php 上看到欢迎来到 CI 页面,但是当我添加测试 Controller 并转到 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/;
}

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

尝试创建一个测试 Controller :

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

但它无法加载,并且我收到 404 响应。

有什么想法吗?

最佳答案

改变

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

关于php - CodeIgniter 路由在 Nginx 下不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46187683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com