折腾LNMP: Nginx + thinkphp5

重装多遍。记录。


一、自己纯装

Nginx 搭配php 要搭配 有php-fpm的。
配置Nginx,样例:


二、 腾讯云全能镜像

解决thinkphp5 + Nginx 访问出现Access denied的方法:

参考原文

  1. 配置权限
    chmod -R 777 目录名
  2. 改php.ini文件
  • 将cgi.fix_pathinfo的值改成1
    vim 进入对应文件 /cgi.fix到这个地方,修改成cgi.fix_pathinfo=1

  • 到nginx.conf中,添加fastcgi_split_path_info ^(.+\.php)(/.+)$

    折腾LNMP: Nginx + thinkphp5_第1张图片
    图示

  • 到配置域名解析的文件下(一般是以域名命名的配置文件)。加上这三句:

fastcgi_split_path_info ^(.+\.php)(/.+)$;  
fastcgi_param   PATH_INFO   $fastcgi_path_info;  
fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;  
折腾LNMP: Nginx + thinkphp5_第2张图片
图示
  • 最后重启nginx和php-fpm
 systemctl restart nginx.service
 systemctl restart php

nginx.conf 样例:

######################## default ############################
  server {
  listen 80;
  server_name _;
  access_log /data/wwwlogs/access_nginx.log combined;
  root /data/wwwroot/default;
  index index.html index.htm index.php;
  location /nginx_status {
    stub_status on;
    access_log off;
    allow 127.0.0.1;
    deny all;
    }
  location ~ [^/]\.php(/|$) {
    #fastcgi_pass remote_php_ip:9000;

# LC add
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
##

    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;

# LC add
    fastcgi_param   PATH_INFO   $fastcgi_path_info;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
##
    }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
    }
  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
    }
  location ~ /\.ht {
    deny all;
    }
  }

########################## vhost #############################
  include vhost/*.conf;
}


测试

我的nginx的root路径是 /data/wwwroot/default,因此摆一个名字为phpinfo.php,内容为:


的php文件。
然后访问[公网ip]/phpinfo.php
可以看见下面的信息:

折腾LNMP: Nginx + thinkphp5_第3张图片
php信息

这个信息表很重要!
配置mongodb时可以在这里看到是否配置好 mongodb的php扩展了。

你可能感兴趣的:(折腾LNMP: Nginx + thinkphp5)