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

Fullcalendar部署到Apache服务器无法定位/data数据源问题求助

问题:FullCalendar 部署到 Apache + CentOS7 后无法加载事件数据

我在本地测试环境中,用 FullCalendar 渲染 Flask 应用返回的事件完全正常,能顺利查询并拿到 JSON 数据。但部署到 CentOS7 的 Apache 服务器后,Apache 日志报错:

AH00128: File does not exist: /etc/httpd/htdocs/data

我的 calendar.html 模板里的 FullCalendar 配置片段是这样的:

<script> 
$(document).ready(function() { 
    $('#calendar').fullCalendar({ 
        header: { 
            left: 'prev,next today', 
            center: 'title', 
            right: 'month,listWeek' 
        }, 
        defaultView: 'listWeek', 
        editable: false, 
        eventLimit: true, // allow "more" link when too many events 
        events: { 
            url: 'data', 
            error: function() { 
                $('#script-warning').show(); 
            } 
        }, 
        loading: function(bool) { 
            $('#loading').toggle(bool); 
        } 
    }); 
}); 
</script>

我知道是 url: 'data' 这行控制请求路径,但试了好几种写法都没用,也没找到其他配置路径的地方。显然 Apache 找的 /etc/httpd/htdocs/data/ 是完全错误的路径,请问该怎么配置才能让 FullCalendar 正常加载数据?

补充:我觉得这是 Apache 配置的问题,我的虚拟主机配置如下:

<virtualhost *:443> 
ServerName server.example.com 
LogLevel info 
SSLEngine On 
SSLProtocol all -SSLv2 -SSLv3 
WSGIDaemonProcess fs_calendar user=apache group=apache threads=5 home=/var/www/fs_calendar/ 
WSGIScriptAlias /fs_calendar /var/www/fs_calendar/calendar.wsgi 

<directory /var/www/fs_calendar> 
WSGIProcessGroup fs_api 
WSGIApplicationGroup %{GLOBAL} 
WSGIScriptReloading On 
WSGIPassAuthorization On 
Order deny,allow 
Allow from all 
</directory> 

Include /etc/letsencrypt/options-ssl-apache.conf 
SSLCertificateFile /etc/letsencrypt/live/server.example.com/cert.pem 
SSLCertificateKeyFile /etc/letsencrypt/live/server.example.com/privkey.pem 
Include /etc/letsencrypt/options-ssl-apache.conf 
SSLCertificateChainFile /etc/letsencrypt/live/server.example.com/chain.pem 
</virtualhost>

解决方案

这个问题核心是相对路径解析错误加上 Apache 虚拟主机挂载配置的小问题,咱们一步步来搞定:

1. 先搞懂请求路径为什么错了

你写的 url: 'data' 是相对路径,它会根据当前页面的 URL 来解析。比如如果你的日历页面是通过 https://server.example.com/fs_calendar/calendar 访问的,那 data 会被解析成 https://server.example.com/fs_calendar/data——这才是正确指向 Flask 应用的路径。但现在 Apache 去 /etc/httpd/htdocs/data 找文件,说明当前页面的基础路径是 Apache 的默认根目录,而不是你的 Flask 应用挂载的 /fs_calendar 前缀。

大概率是你的日历页面要么是直接放在 Apache 根目录(/etc/httpd/htdocs)里访问的,要么相对路径没有带上应用的挂载前缀。

2. 修正 FullCalendar 的请求 URL(最关键的一步)

有两种可靠的写法,选一个适合你的:

  • 绝对路径(简单直接):直接写完整的 Flask 路由路径,结合你的 Apache 挂载前缀 /fs_calendar,把配置改成:
    url: '/fs_calendar/data'
    
    这样不管当前页面在哪里,都会直接请求 https://server.example.com/fs_calendar/data,彻底避免路径解析错误。
  • 动态生成路径(更灵活):如果你怕以后改挂载前缀麻烦,或者想让路径自动适配,可以用 Flask 的 url_for 函数在模板里生成正确的路径。比如你的 Flask 里处理数据的路由是:
    @app.route('/data')
    def get_events():
        # 返回事件JSON数据
        ...
    
    那在模板里就可以写成:
    url: "{{ url_for('get_events') }}"
    
    Flask 会自动根据当前的 Apache 挂载配置生成正确的 URL,不用硬编码前缀。

3. 修复 Apache 虚拟主机的配置细节

看你的配置里有个小漏洞:你定义的 WSGIDaemonProcess 叫 fs_calendar,但 <directory> 块里写的是 WSGIProcessGroup fs_api,这会导致进程组不匹配,可能影响请求的转发。把 <directory> 里的 WSGIProcessGroup fs_api 改成 WSGIProcessGroup fs_calendar,保持一致。

4. 验证基础路径是否正确

如果你的日历页面是直接放在 Apache 根目录(/etc/httpd/htdocs)里,通过 https://server.example.com/calendar.html 访问的,那相对路径 data 肯定会指向 /data——而这个路径没有被映射到 Flask 应用,所以 Apache 会去默认根目录找文件。这种情况要么把页面移到 Flask 应用里,通过路由返回;要么就用上面说的绝对路径写法。

最后,改完配置记得重启 Apache 生效:

sudo systemctl restart httpd

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:48:59