【问题标题】:CodeIgniter 3, Nginx rewrite how to?CodeIgniter 3、Nginx 怎么改写?
【发布时间】:2017-01-14 03:35:58
【问题描述】:

我在 PHP-fpm 和 nginx (Ubuntu) 上安装了 CodeIgniter 3。以前我一直在 Windows 上使用 CodeIgniter,在 Windows 和 Apache 上配置它是小菜一碟。 现在我想在 nginx 上安装它,因为我想使用 nginx-push-stream-module,这在 apache 中是不可能的。

现在当我配置它时,它不起作用。

如果我输入 localhost/myexample.comlocalhost/myexample.com/index.php 它会起作用(myexample.com 是该目录的名称)

但是当我尝试访问时

localhost/myexample.com/welcome

localhost/myexample.com/welcome/index

localhost/myexample.com/index.php/welcome

localhost/myexample.com/index.php/welcome/index

它在 4 种情况下都不起作用(有或没有 index.php)

我的根目录是/var/www/html/myexample.com

我尝试了来自不同博客文章等的所有在线可用的重写设置(包括以下设置)(因为我自己不习惯 nginx)

server {
    server_name myexample.com;
    root /var/www/html/myexample.com/;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
        expires           15d;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html/myexample.com/index.php;
        fastcgi_param  REQUEST_URI      $request_uri;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
     }
}

编辑:我也尝试过 Nginx 官网提到的the method,但也不起作用。

【问题讨论】:

    标签: php codeigniter nginx url-rewriting


    【解决方案1】:

    你应该修改你的 /etc/hosts 并添加这一行:

    127.0.0.1 myexample.com

    然后使用 myexample.commyexample.com/welcome 访问您的 CodeIgniter 站点

    【讨论】:

      【解决方案2】:

      首先 - 确认服务器名称将是什么。在您的主机文件中设置它,然后确认 Web 根目录。

      所以在 /etc/hosts 添加

      127.0.0.1 myexample.com
      

      那么你的 index.php 文件应该在

      /var/www/html/myexample.com/
      

      你应该启动 CI 并处理 url

      http://myexample.com
      

      【讨论】:

        猜你喜欢
        • 2016-05-08
        • 2015-03-04
        • 2017-01-18
        • 2013-10-21
        • 2020-06-03
        • 2016-02-18
        • 2021-08-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多