配置文件如下:
#因为我没有把public文件设置为主目录 所以更改了一下,我的是lnmp 安装包
server
{
listen 80 default_server;
#listen [::]:80 default_server ipv6only=on;
server_name _;
index index.html index.htm index.php;
root /home/wwwroot/default;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location / {
index index.php index.html index.htm;
#如果请求既不是一个文件,也不是一个目录,则执行一下重写规则
if (!-e $request_filename)
{
#地址作为将参数rewrite到index.php上。
#rewrite ^/(.*)$ /index.php?s=$1;
#若是子目录则使用下面这句,将subdir改成目录名称即可。
rewrite ^/public/(.*)$ /public/index.php?s=$1;
}
}
location /api/ {
index index.php index.html index.htm;
#如果请求既不是一个文件,也不是一个目录,则执行一下重写规则
if (!-e $request_filename)
{
#地址作为将参数rewrite到index.php上。
#rewrite ^/(.*)$ /index.php?s=$1;
#若是子目录则使用下面这句,将subdir改成目录名称即可。
rewrite ^/api/(.*)$ /api/index.php?s=$1;
}
}
location ~* ^\/upload\/.+\.(html|php)$ {
return 404;
}
location ~* ^\/plugins\/.+\.(html|php)$ {
return 404;
}
location ~* ^\/themes\/.+\.(html|php)$ {
return 404;
}
#proxy the php scripts to php-fpm
location ~ \.php {
include fastcgi_params;
##pathinfo支持start
#定义变量 $path_info ,用于存放pathinfo信息
set $path_info "";
#定义变量 $real_script_name,用于存放真实地址
set $real_script_name $fastcgi_script_name;
#如果地址与引号内的正则表达式匹配
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
#将文件地址赋值给变量 $real_script_name
set $real_script_name $1;
#将文件地址后的参数赋值给变量 $path_info
set $path_info $2;
}
#配置fastcgi的一些参数
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
###pathinfo支持end
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
# fastcgi_pass 如果是 sock形式,可能是下面的配置
# fastcgi_pass unix:/tmp/php-cgi.sock
}
access_log /home/wwwlogs/access.log;
}
之后因为需要开启fileinfo扩展,所以进行一下操作步骤:
Centos 下编译安装fileinfo扩展
0.why complie fileinfo extension
今天有同事要去做功能,发现php当初安装的时候未编译fileinfo扩展
但使用pecl install 出现找不到.m4文件等等其他较琐碎的安装失败问题。 所以还是中规中矩的使用phpize来安装扩展吧。
1.检查当前环境
php -i|grep fileinfo 若出现 fileinfo fileinfo support => enabled 则代表fileinfo扩展可用,否则不可用。
2.安装
2-1:下载(自己php版本的压缩包 php -m 查看php版本 ,我的是7.0.21)
wget -O php-7.0.21.tar.gz http://cn2.php.net/get/php-7.0.21.tar.gz/from/this/mirror
2-2:解压
tar -zxvf php-7.0.21.tar.gz
2-3:进入对应php版本扩展目录(我这是7.0.21版本)
命令 :cd /usr/local/php/include/php/ext/fileinfo/
2-4:编译&&安装
命令 : /usr/local/php/bin/phpize
如果安装出错,可能是因为你解压的目录不在 /usr/local/php/include/php/ext/fileinfo/,输入以下命令复制到php扩展所在目录,命令如下:
cp -Rf /php-7.0.21/ext/fileinfo/* /usr/local/php/include/php/ext/fileinfo/
如果不知道自己解压到哪里 使用命令 find / -name fileinfo查找到问价目录。
如果php扩展目录没有fileinfo 目录就新建一个。
2. ./configure -with-php-config=/usr/local/php/bin/php-config
3. make && make install
4. vim /usr/local/php/etc/php.ini
5.
2-5:修改php.ini
加入:extension=fileinfo.so
2-6:重启nginx
service nginx restart