在 Ubuntu 系统中,配置 ThinkPHP 的静态资源可以通过以下步骤实现:
sudo apt-get update
sudo apt-get install nginx
sudo apt-get install php-fpm
/etc/nginx/sites-available 目录下创建一个新文件,例如 thinkphp.conf:sudo nano /etc/nginx/sites-available/thinkphp.conf
server {
listen 80;
server_name example.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$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock; # 根据你的 PHP 版本进行修改
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
保存并关闭配置文件。
创建一个符号链接,将新创建的配置文件链接到 sites-enabled 目录:
sudo ln -s /etc/nginx/sites-available/thinkphp.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
现在,你的 ThinkPHP 项目应该可以正确处理静态资源了。如果你遇到任何问题,请检查 Nginx 和 PHP-FPM 的日志文件以获取更多信息。