You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel Forge部署问题:Nginx配置文件不存在及部署参数咨询

解决Laravel Forge部署时「No such file directory」错误的配置方案

一、正确的Deploy Script配置

替换Forge默认部署脚本为以下内容(根据项目实际情况调整分支名和路径):

cd /home/forge/your-project-domain.com
git pull origin main

# 安装生产环境依赖
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev

# Laravel核心缓存操作
php artisan config:cache
php artisan route:cache
php artisan view:cache

# 修复目录权限
chmod -R 775 storage bootstrap/cache
chown -R forge:forge storage bootstrap/cache

# 可选:数据库迁移(加--force跳过交互)
# php artisan migrate --force

# 可选:重启队列Worker
# php artisan queue:restart

# 重启PHP-FPM使变更生效
sudo service php8.2-fpm reload

注意:

  • 第一行的/home/forge/your-project-domain.com必须和Forge站点的项目路径完全一致,路径错误是触发「No such file directory」的高频原因。
  • 将main替换为你实际使用的代码分支(如master),PHP版本php8.2-fpm需和你在Forge中安装的版本匹配。

二、正确的Nginx配置

进入「Edit Files」→「Edit nginx configuration」,替换为以下核心配置(替换域名和项目路径):

server {
    listen 80;
    listen [::]:80;
    server_name your-project-domain.com;
    root /home/forge/your-project-domain.com/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm 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_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

关键要点:

  • root必须指向项目的public子目录,绝对路径要和Forge站点设置里的「Root Directory」完全匹配,这是Nginx找不到文件的核心原因。
  • fastcgi_pass中的PHP版本需和服务器安装的PHP版本一致。

额外排查动作

  1. 确认Forge站点设置的「Root Directory」是public,而非项目根目录。
  2. 登录服务器终端,执行ls /home/forge/your-project-domain.com验证项目文件存在,且public目录不为空。
  3. 检查storage和bootstrap/cache目录权限,确保forge用户拥有读写权限。

内容的提问来源于stack exchange,提问作者doklin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 09:27:24