Hex 发表于 2016-10-11 10:16:30

萧然 发表于 2016-10-10 22:32
我的是nginx1.8

nginx 参考 https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/ 设置一下

alben_001 发表于 2016-10-11 11:19:32

你在index.php 第一行添加一句:
$_SERVER['SCRIPT_NAME'] = '/index.php';
试试,服务器配置方式问题,以前通过修改uri部分找到的问题,仅供参考。

hbualong 发表于 2016-10-11 15:33:10

应该是你的访问方式有问题,

燃雲 发表于 2016-10-11 17:09:39

猜想...

并非默认,是404。

萧然 发表于 2016-10-11 22:28:37

alben_001 发表于 2016-10-11 11:19
你在index.php 第一行添加一句:
$_SERVER['SCRIPT_NAME'] = '/index.php';
试试,服务器配置方式问题,以 ...

放在index.php第一行也不行啊,出现404 Page Not Found The page you requested was not found.

萧然 发表于 2016-10-11 22:31:03

hbualong 发表于 2016-10-11 15:33
应该是你的访问方式有问题,

http://www.yhuweb.com/play_ci/index.php/cismarty/test这是我自己机器上的地址,cismarty是控制器类名(当然类名首字母大写),test是类里的方法

萧然 发表于 2016-10-11 22:31:39

燃雲 发表于 2016-10-11 17:09
猜想...

并非默认,是404。

什么意思,没明白?

萧然 发表于 2016-10-11 22:40:25

Hex 发表于 2016-10-11 10:16
nginx 参考 https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/ 设置一下


#usernobody;
worker_processes1;

#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;

#pid      logs/nginx.pid;


events {
    worker_connections1024;
}


http {
    include       mime.types;
    default_typeapplication/octet-stream;

    client_max_body_size 20M; #修改此处上传大小为自己实际需要的大小

    #log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_loglogs/access.logmain;

    sendfile      on;
    #tcp_nopush   on;

    #keepalive_timeout0;
    keepalive_timeout65;

    #gzipon;

    server {
      listen       80;
      server_namewww.yhuweb.com;

      #charset koi8-r;

      #access_loglogs/host.access.logmain;

      location / {
            root   D:/wnmp/www;
            indexindex.html index.php;
#          if (-f $request_filename) {
#             expires max;
#             break;
#           }
#           if (!-e $request_filename) {
#             rewrite ^/(.*)$ /index.php/$1 last;
#           }
      }
               
      #error_page404            /404.html;

      # redirect server error pages to the static page /50x.html
      #
      error_page   500 502 503 504/50x.html;
      location = /50x.html {
            root   D:/wnmp/www;
      }

      # proxy the PHP scripts to Apache listening on 127.0.0.1:80
      #
      #location ~ \.php$ {
      #    proxy_pass   http://127.0.0.1;
      #}

      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
      #
                location /phpmyadmin {
                        alias D:/wnmp/www/phpmyadmin;
                        index index.php;
                }
               
      location ~ \.php$ {
            root         D:/wnmp/www;
            fastcgi_pass   127.0.0.1:9090;
            fastcgi_indexindex.php;
            fastcgi_paramSCRIPT_FILENAMED:/wnmp/www$fastcgi_script_name;
            include      fastcgi_params;
      }

      # deny access to .htaccess files, if Apache's document root
      # concurs with nginx's one
      #
      #location ~ /\.ht {
      #    denyall;
      #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_namesomenamealiasanother.alias;

    #    location / {
    #      root   html;
    #      indexindex.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_namelocalhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_keycert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout5m;

    #    ssl_ciphersHIGH:!aNULL:!MD5;
    #    ssl_prefer_server_cipherson;

    #    location / {
    #      root   html;
    #      indexindex.html index.htm;
    #    }
    #}

}
*********************************************************
这是我的nginx全部配置。
$config['base_url']        = 'http://'.$_SERVER['HTTP_HOST'].'/play_ci';
ci命名为play_ci,放在根目录下;
$config['uri_protocol']        = 'AUTO';
AUTO和REQUEST_UR设置I都试过了;
$route['default_controller'] = 'cismarty';routes.php下默认控制器的配置


*********************************************************
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Cismarty extends CI_Controller {
function __construct()
{
   parent::__construct();
}
function index()
{
   $this->test();
}

public function test()
{
   $this->tpl->assign("content","恭喜你smarty安装成功!");
   $this->tpl->display('smarty_view.html');
}
}
这是我自定义的控制器代码;
自己在浏览器中访问时
http://www.yhuweb.com/play_ci/index.php/cismarty/test
结果是404 Not Found

Hex 发表于 2016-10-11 23:52:23

萧然 发表于 2016-10-11 22:40
#usernobody;
worker_processes1;


你按照我给你的配置试试。

另外,控制器文件名也要首字母大写。
你的问题肯定是某个小问题引起的,建议你仔细找找,因为我这里都是OK的,CI 中国服务器就是按照 nginx 官方提供的设置弄的。

燃雲 发表于 2016-10-12 04:58:05

Hex 发表于 2016-10-11 23:52
你按照我给你的配置试试。

另外,控制器文件名也要首字母大写。


除此以外,看看User有无index()。

LNMP还要看目录及文件的系统及Nginx访问权等等。

这些是404方向的想法。
页: 1 [2] 3 4
查看完整版本: 为什么我的ci一直访问的是默认控制器???