本文章适用于Debian 或Ubantu 系统
- 获取ThinkPHP 框架
# 通过git获取
git clone https://github.com/top-think/think tp5 #获取应用项目
git clone https://github.com/top-think/framework thinkphp #获取核心框架
- 安装Nginx
apt-get install -y nginx-extras
- 使用nginx默认配置文件情况下 文件地址: /etc/nginx/sites-available/default
网站根目录设置到thinkPHP框架public/文件夹下较为方便
默认访问文件类型内添加index.php
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/public; #网站根目录
rewrite ^(.*) https://$server_name$1 permanent;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php; #默认访问文件类型
server_name ufinderfeedback.u-nas.cn;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
# deny access to .htaccess files, if Apache's document root
#location ~ /\.ht {
# deny all;
#}
}
- nginx默认安装不支持 php, 需安装fpm
# php5 情况下
apt-get install php5-fpm
# php7 情况下
apt-get install php7.0-fpm
在 /etc/nginx/sites-available/default 文件中
取消 include snippets/fastcgi-php.conf; 及fastcgi_pass unix:/var/run/php5-fpm.sock; 两行前面的注释
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
- 访问时隐藏index.php及让nginx支持完整路由访问
修改nginx默认配置文件
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# 加入以下三行代码 支持隐藏index.php访问
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
#加入下两行 支持完全路由访问模式
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
- 修改thinkphp框架下文件夹runtime的权限
chmod 777 ./runtime/
-
https访问 参照 Let’s Encrypt 申请免费ssl证书 及 服务器配置 该篇文章
-
设置完https之后访问,可能会出现跳转至"https://_"该网站,清除浏览器缓存即可