Linux上部署 Laravel 的实用步骤
一 环境准备
二 获取代码与安装依赖
三 Web 服务器配置
server { listen 80; server_name yourdomain.com; root /var/www/yourapp/public; index index.php index.html; charset utf-8;
add_header X-Frame-Options “SAMEORIGIN”; add_header X-XSS-Protection “1; mode=block”; add_header X-Content-Type-Options “nosniff”;
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; # 按实际 PHP 版本调整 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; }
location ~ /.(?!well-known).* { deny all; } }
启用站点并重启:sudo ln -s /etc/nginx/sites-available/yourdomain /etc/nginx/sites-enabled/ && sudo nginx -t && sudo systemctl restart nginx
四 文件权限与目录所有权
五 队列与自动化部署