ThinkPHP 框架项目部署在Linux Nginx环境下注意点

本文章适用于Debian 或Ubantu 系统

  1. 获取ThinkPHP 框架
# 通过git获取
git clone https://github.com/top-think/think tp5            #获取应用项目
git clone https://github.com/top-think/framework thinkphp   #获取核心框架
  1. 安装Nginx
apt-get install -y nginx-extras
  1. 使用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;
        #}
}
  1. 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;
        }
  1. 访问时隐藏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;
        }
  1. 修改thinkphp框架下文件夹runtime的权限
chmod 777 ./runtime/ 
  1. https访问 参照 Let’s Encrypt 申请免费ssl证书 及 服务器配置 该篇文章

  2. 设置完https之后访问,可能会出现跳转至"https://_"该网站,清除浏览器缓存即可

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值