簡體   English   中英

Codeigniter Nginx控制器函數返回404

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM