在CentOS环境下部署ThinkPHP静态资源,可以遵循以下步骤:
首先,确保已经安装了Nginx。如果尚未安装,请按照以下命令进行安装:
sudo yum install epel-release
sudo yum install 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项目中,将静态资源(如CSS、JavaScript、图片等)放置在public目录下。例如:
/your/thinkphp/project/public/css
/your/thinkphp/project/public/js
/your/thinkphp/project/public/img
保存配置文件并重启Nginx以应用更改:
sudo systemctl restart nginx
现在,你应该可以通过访问http://your_domain.com/static/css/style.css(将URL替换为实际的静态资源路径)来访问ThinkPHP项目中的静态资源了。