折腾LNMP: Nginx + thinkphp5

2017-12-24  本文已影响0人  AbbyLC

重装多遍。记录。


一、自己纯装

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


二、 腾讯云全能镜像

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

参考原文

  1. 配置权限
    chmod -R 777 目录名
  2. 改php.ini文件
fastcgi_split_path_info ^(.+\.php)(/.+)$;  
fastcgi_param   PATH_INFO   $fastcgi_path_info;  
fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;  
图示
 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
  phpinfo() 
?>

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

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

猜你喜欢

热点阅读