下面给你一个在 Debian 上用 Nginx 运行 Laravel 的标准、可落地配置流程(假设你用的是 Debian 11/12 + PHP 8.1/8.2 + Nginx)。
sudo apt update
sudo apt install -y nginx php-fpm php-cli php-mysql php-mbstring php-xml php-curl php-zip php-gd unzip
如果你是 PHP 8.2:
sudo apt install -y php8.2-fpm
确认 PHP-FPM 已运行:
systemctl status php8.2-fpm
例如项目放在:
/var/www/laravel
设置权限(⚠️ 很重要):
sudo chown -R www-data:www-data /var/www/laravel
sudo chmod -R 755 /var/www/laravel
sudo chmod -R 775 /var/www/laravel/storage
sudo chmod -R 775 /var/www/laravel/bootstrap/cache
新建配置文件:
sudo nano /etc/nginx/sites-available/laravel
server {
listen 80;
server_name example.com; # 改成你的域名或服务器IP
root /var/www/laravel/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
sudo ln -s /etc/nginx/sites-available/laravel /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
cd /var/www/laravel
cp .env.example .env
php artisan key:generate
php artisan storage:link
root 指向错误(必须是 public)www-dataphp-fpm.sock 路径错误ls /run/php/
csrftry_filessudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com
如果你愿意,我可以:
直接说你的环境即可。