阅读量:2
在CentOS环境下部署ThinkPHP静态资源,可以遵循以下步骤:
- 安装Nginx
首先,确保已经安装了Nginx。如果尚未安装,请按照以下命令进行安装:
sudo yum install epel-release
sudo yum install nginx
- 配置Nginx
编辑Nginx配置文件,通常位于/etc/nginx/nginx.conf或/etc/nginx/conf.d/default.conf。在server块中,添加以下配置:
server {
listen 80;
server_name your_domain.com; # 替换为你的域名或公网IP
root /path/to/your/thinkphp/project; # 替换为你的ThinkPHP项目路径
index index.php index.html index.htm;
location /
{
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$
{
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht
{
deny all;
}
}
- 配置ThinkPHP静态资源
在ThinkPHP项目中,将静态资源(如CSS、JavaScript、图片等)放置在public目录下。例如:
/your/thinkphp/project/public/css
/your/thinkphp/project/public/js
/your/thinkphp/project/public/img
- 重启Nginx
保存配置文件并重启Nginx以应用更改:
sudo systemctl restart nginx
现在,你应该可以通过访问http://your_domain.com/static/css/style.css(将URL替换为实际的静态资源路径)来访问ThinkPHP项目中的静态资源了。
以上就是关于“centos环境下thinkphp如何部署静态资源”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm