在PHP-fpm和nginx (Ubuntu)上安装了很长时间后,我安装了CodeIgniter 3。以前我一直在Windows上使用CodeIgniter,在Windows和Apache上配置它是小菜一碟。现在我想把它安装在nginx上,因为我想使用nginx-push-stream-module,这在apache中是不可能的。
现在当我配置它时,它不工作。
如果我输入localhost/myexample.com
或localhost/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的官方网站上提到的方法,但这也不起作用
您应该修改/etc/hosts并添加以下行:
127.0.0.1 myexample.com
然后使用myexample.com或myexample.com/welcome访问CodeIgniter站点
首先确认服务器名称。在hosts文件中设置,然后确认web根目录。
在/etc/hosts中添加127.0.0.1 myexample.com
那么你的index。php文件应该在
/var/www/html/myexample.com/
你应该启动CI并处理url
http://myexample.com