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

Laravel 11 + Inertia Vue部署至服务器后Web路由404问题求助

Laravel 11 + Inertia Vue 部署后 Admin 路由404排查方案

1. 服务器重写规则配置问题

  • 确认服务器(Nginx/Apache)是否正确配置URL重写,Laravel需要将所有请求导向public/index.php:
    • Nginx:检查配置文件是否包含以下规则,同时确认/admin路径未被特殊规则拦截:
      location / {
          try_files $uri $uri/ /index.php?$query_string;
      }
      
    • Apache:确保public/.htaccess已上传,且Apache启用mod_rewrite模块,虚拟主机配置中设置AllowOverride All允许.htaccess生效。

2. Inertia 路由与资源配置问题

  • 检查routes/web.php中admin路由的定义,确保正确使用Inertia渲染方法:
    Route::prefix('admin')->group(function () {
        Route::get('/', fn () => Inertia::render('Admin/Dashboard'));
        // 其他admin路由...
    });
    
  • 确认resources/js/app.js中Inertia的组件解析路径正确:
    createInertiaApp({
        resolve: name => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
        // 其他配置
    })
    
  • 部署时必须执行npm run build生成生产环境静态资源,并确保public/build目录已完整上传到服务器。

3. 缓存清理操作

  • 清理Laravel路由缓存:
    php artisan route:clear
    
  • 若部署时生成过路由缓存,更新路由后重新生成:
    php artisan route:cache
    
  • 清理服务器opcache缓存(若启用),避免旧路由配置残留。

4. 目录权限检查

  • 确保服务器上storage和bootstrap/cache目录权限正确:
    chmod -R 755 storage bootstrap/cache
    chown -R www-data:www-data storage bootstrap/cache # 根据服务器运行用户调整
    

5. HTTPS重定向验证

  • 若服务器启用HTTPS,检查是否存在强制HTTPS的规则导致路由匹配异常,确保重定向逻辑不会干扰admin路径的访问。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 22:22:35