百度云虚拟主机(BCH)部署thinkcmf框架

作者:stoat 发布时间:2020-12-17 分类:技术

百度云主机后台是无法直接设置thinkcmf框架运行目录的,需要手动配置bcloud_nginx_user.conf文件,没错,百度云主机是基于nginx搭建的。

以下为百度云虚拟主机(BCH)部署thinkcmf框架的具体代码,分为网站和API前端,都有写。具体可以参考框架自身的nginx环境配置。


location / {
    root /home/bae/app/public;
 
    if (-e $document_root/index.php) {
          rewrite ^/(.*)$ /index.php/$1?$query_string last; 
    }
 
    return 404;
}
 
## php配置
location ~ [^/]\.php(/|$){
    root /home/bae/app/public;
    fastcgi_index               index.php;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_intercept_errors    on;
    fastcgi_split_path_info       ^(.+\.php)(.*)$;   
    fastcgi_param PATH_INFO       $fastcgi_path_info;    
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;    
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;
 
    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param  REQUEST_URI        $request_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      $document_root;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;
    fastcgi_param  REQUEST_SCHEME     $scheme;
    fastcgi_param  HTTPS              $https if_not_empty;
 
    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
 
    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;
    fastcgi_param  SERVER_NAME        $server_name;
 
    # PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param  REDIRECT_STATUS    200;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico|eot|otf|ttf|woff|woff2|svg|xml)$ {
   root /home/bae/app/public;
   expires 30d;
   access_log off;
}
location ~ .*\.(js|css|txt)?$ {
   root /home/bae/app/public;
   expires 7d;
   access_log off;
}
location ~ /\.ht {
   root /home/bae/app/public;
   deny all;
}
 
## 禁止敏感文件的直接访问
location ~* \.(inc|bak|sql|lua|so|ini|conf)$ {
    deny all;
}

location /api/ {
    root /home/bae/app/public;
    index  index.php index.html index.htm;
     #如果请求既不是一个文件,也不是一个目录,则执行一下重写规则
     if (!-e $request_filename)
     {
        #若是子目录则使用下面这句,将subdir改成目录名称即可。
        rewrite ^/api/(.*)$ /api.php/$1?$query_string last; 
     }
}

原文地址:百度云虚拟主机(BCH)部署thinkcmf框架 by 雪鼬博客

标签:none

评论已关闭