首页 > 其他分享 >Caddy设置try_files导致handle配置失效

Caddy设置try_files导致handle配置失效

时间:2023-11-28 11:33:22浏览次数:26  
标签:files index handle Caddy try html

问题

Caddy中,请求路径默认会在Caddy的路径中查找。然而,如果是Vue项目,URI通常会是路由,如果此时刷新页面就可能导致页面出错。

因此,我们可以使用 try_files 来在页面找不到时重定向到index.html

try_files {path} /index.html;

然而,加入这种配置会导致 handle 的监听路径冲突,从而使handle配置失效。

解决方法

为了解决这个问题,我们可以将 try_files {path} /index.html 配置单独放在 handle 中。这样既可以使API请求正常生效,又不会影响路由的配置。

handle /api/* {
    reverse_proxy localhost:30000
}

handle {
    file_server
    try_files {path} /index.html
}

这样的配置使得 try_files 只在特定的路径下生效,保持了handle配置的有效性。

标签:files,index,handle,Caddy,try,html
From: https://www.cnblogs.com/hemin809/p/17861513.html

相关文章

  • yarn : 无法加载文件 C:\Program Files\nodejs\yarn.ps1,因为在此系统上禁止运行
    问题分析:这个错误提示说明在电脑系统上禁止运行PowerShell 脚本,因此导致无法加载Yarn的安装脚本。这是由于系统的执行策略(ExecutionPolicies)设置所导致的。解决方法:1.以管理员身份运行PowerShell。2.在窗口中执行 set-ExecutionPolicyRemoteSigned。3.执行完成后,......
  • Backing up and restoring BIG-IP configuration files (10.x)
    TopicThisarticleappliestoBIG-IP10.x.Forinformationaboutotherversions,refertothefollowingarticles:K13132:BackingupandrestoringBIG-IPconfigurationfiles(11.x-13.x)K3499:BackingupandrestoringBIG-IPconfigurationfiles(9.x)Thi......
  • Filesystem type ntfs3,ntfs not configured in kernel
    title:Filesystemtypentfs3,ntfsnotconfiguredinkernelbanner_img:https://cdn.studyinglover.com/pic/2023/07/6eb76e56ebdd72a1bbcb48f4a19cc0da.pngdate:2023-7-149:35:00categories:-踩坑Filesystemtypentfs3,ntfsnotconfiguredinkernel昨天卸载硬盘......
  • DeprecationWarning:on_event is deprecated, use lifespan event handlers instead.
    问题说明:fastapi启动之前执行代码,旧版本使用的是@app.on_event("startup"),不过在已经不推荐使用@app.on_event("startup")asyncdefstartup_db():create_all()问题处理通过lifespanevent配合contextlib实现。修改后代码:fromcontextlibimportasynccontextmanag......
  • 普通全局异常存在的问题 GlobalExceptionHandler
    简单搭建Feign框架parent<dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId>......
  • Handler 源码解析,从入门到几乎入门
    AndroidHandler源码解析在Android中,Handler是一种强大的机制,用于在不同的线程之间进行通信。通过Handler,你可以轻松地将任务从一个线程发送到另一个线程,通常用于在后台线程执行任务后更新UI。同时handler机制也是Android主线程运行的原理,了解了主线程的运行原理也就可以知道l......
  • uniapp开发[Vue warn]: Unhandled error during execution of scheduler flush. This
    如下,uniapp开发nvue页面报如下警告:15:30:25.079[Vuewarn]:Unhandlederrorduringexecutionofrenderfunctionat<UniGroupclass="w710cell_groupbg_whiteborder_radius16flex_row"top="10">at<Index__pageId=1__pagePath="pages/g......
  • caddy 替代nginx? caddy测试体验
    安装官网:https://caddyserver.com帮助文档:https://caddy2.dengxiaolong.com/docs/runningcadddy也是一个守护进程的前后台守护应用,后台服务一直监听cli的操作所有所有的service的操作都支持优势目前来看caddy的的优势是==nignx+acme.shUbuntu下安装sudoaptinstall-......
  • [949] Using re to extract unstructured tables of PDF files
    Hereistheproblem,thisunstructuredtableofaPDFfilecannotbeextrctedasatabledirectly.Wecanonlyextractthewholetextsofeverypage.MytaskistoextractthePlaceID,PlaceName,andTitleDetails.ThenonlyTitleDetailsincludepatte......
  • UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '??=' 报错处理
    在用vite创建react的时候install完成后输入pnpmrundev突然蹦出UnhandledPromiseRejectionWarning:SyntaxError:Unexpectedtoken'??='一脸闷逼,百度了一下。哦吼,逻辑空赋值(??=)是ES2021的语法,nodev15.0.0以上才支持逻辑空赋值(??=)的语法。之前为了兼容旧代码使用的n......