在Debian上處理Laravel靜態資源,你需要遵循以下步驟:
首先,確保你已經安裝了Nginx和PHP-FPM。如果沒有,請使用以下命令安裝:
sudo apt-get update
sudo apt-get install nginx
sudo apt-get install php-fpm
編輯Nginx配置文件,通常位于/etc/nginx/sites-available/default
。在server
塊中,配置Laravel項目的靜態資源目錄和PHP處理。例如:
server {
listen 80;
server_name example.com;
root /var/www/laravel_project/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
請確保將server_name
更改為你自己的域名,將root
更改為你的Laravel項目的public
目錄。
確保Laravel項目的storage
和bootstrap/cache
目錄具有可寫權限。你可以使用以下命令設置權限:
sudo chown -R www-data:www-data /var/www/laravel_project/storage
sudo chown -R www-data:www-data /var/www/laravel_project/bootstrap/cache
保存更改后,重啟Nginx以應用新配置:
sudo systemctl restart nginx
現在,你的Laravel應用程序應該可以在Debian上正確處理靜態資源了。如果你遇到任何問題,請檢查Nginx和PHP-FPM的錯誤日志,以獲取有關問題的詳細信息。