drpp5680 2018-12-05 21:42 采纳率: 0%
浏览 152

如何缓存PHP生成的静态JS文件

I am specifically using the email automation software Mautic. Mautic has a JS tracking code that is dynamically generated (/mtc.js), but the generation isn't cached. I'm using nginx as my webserver.

The logical thing to do here is to use fastcgi_cache to cache the outputs of the file. How can I use fastcgi_cache to cache a the JS file that is generated by PHP? Is there a better alternative?

Here are the relevant parts of my vhost (excluding Cerbot stuff):

fastcgi_cache_path /var/www/mail.zachrussell.net/cache levels=1:2 keys_zone=mail.zachrussell.net:100m inactive=60m;
fastcgi_buffers 16 16k; 
fastcgi_buffer_size 32k;
server {
    server_name mail.zachrussell.net www.mail.zachrussell.net;

    access_log /var/www/mail.zachrussell.net/logs/access.log;
    error_log /var/www/mail.zachrussell.net/logs/error.log;

    root /var/www/mail.zachrussell.net/public;
    index index.php;

    set $skip_cache 0;


    if ($request_method = POST) {
        set $skip_cache 1;
    }   
    if ($query_string != "") {
        #set $skip_cache 1;
    }   

    location / {
        try_files $uri $uri/ /index.php?$args; 
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_cache_bypass $skip_cache;
        fastcgi_no_cache $skip_cache;
        fastcgi_cache mail.zachrussell.net;
        fastcgi_cache_valid 60m;
    } 
    [... certbot stuff ...]
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?