# OpenLiteSpeed vhost for app.rangook.ir  (OLS 1.8.5 under aaPanel)
#
# This is the LIVE config with ONE block changed: `expires`. Everything else
# is byte-for-byte what is already on the server. Diff it before pasting.
#
# ---------------------------------------------------------------------------
# WHY ONLY THE expires BLOCK
#
# OLS has no mod_headers, so `Header set` in .htaccess is parsed and silently
# discarded -- that is why no Cache-Control ever reached users. The obvious
# fix is `context {}` blocks with extraHeaders, but that changes how the
# docroot is served and risks interfering with the aaPanel-managed rewrite /
# proxy includes below. The `expires` block is already present and PROVEN
# working on this vhost (text/css and application/x-font-ttf were both
# returning max-age=43200 in production), so extending it is a config change
# with no structural risk.
#
# ---------------------------------------------------------------------------
# THE BUG IN THE CURRENT expires BLOCK
#
# The old line listed `application/javascript` and `application/x-javascript`.
# OLS serves .js files as `text/javascript`. The type never matched, so every
# JavaScript file in the app -- the whole bundle -- got no cache header, while
# CSS and fonts were correctly cached. Verified against production:
#
#   text/css         -> cache-control: public, max-age=43200   (worked)
#   application/x-font-ttf -> public, max-age=43200            (worked)
#   text/javascript  -> no header at all                       (missed)
#
# ---------------------------------------------------------------------------
# WHAT THE NEW LINE DOES
#
#   text/html=A0        The fix for the stale-app bug. Without any
#   text/plain=A0       Cache-Control, a response carrying only ETag /
#   application/json=A0 Last-Modified is not "uncacheable" -- browsers apply
#                       heuristic freshness (~10% of the document's age), so
#                       a month-old file is held for days with no request to
#                       the server. The HTTP cache is keyed per URL, which is
#                       why /home/ could be current while /course/view/ was
#                       weeks stale. A0 = expires at access time, which emits
#                       max-age=0 and forces revalidation on every load.
#                       The origin already answers If-None-Match with 304, so
#                       this costs a ~300 byte conditional request, not a
#                       re-download.
#
#                       text/plain covers the .txt RSC payloads that Next 16's
#                       App Router fetches on client-side navigation -- a
#                       second, independent channel for stale route content.
#                       application/json covers version.json, which the
#                       in-app update check polls.
#
#   text/javascript=    Hashed build assets. Names are content-hashed per
#     A86400            build AND next.config.ts's deploymentId appends
#   text/css=A86400     ?dpl=<buildId>, so a given URL's bytes can never
#                       change -- which in principle justifies a year, and
#                       this was A31536000 (365 days) until 2.3.5.
#
#                       Deliberately lowered to A86400 (1 DAY) while the new
#                       update system stabilises. The reasoning is not that a
#                       year is wrong; it is that a year is unforgiving. If a
#                       chunk ever turns out not to be as immutable as the
#                       hashing implies, a year-long TTL strands every client
#                       that cached it for a year, and nothing server-side can
#                       reach them -- the browser simply stops asking. One day
#                       bounds that blast radius to 24 hours.
#
#                       The cost is one conditional request per asset per day.
#                       The origin answers If-None-Match with a 304, so that
#                       is ~300 bytes, not a re-download.
#
#                       RAISE IT BACK to A31536000 once a few releases have
#                       gone out clean. Update the [5] assertion in
#                       scripts/verify-deploy.sh at the same time -- it checks
#                       the value is sane, so the two must move together.
#
#   image/*, font/*     30 days. Not content-hashed, but they change rarely.
#     =A2592000
#
# NOTE: A0 yields `max-age=0` rather than `no-cache, must-revalidate`. Every
# browser revalidates at max-age=0, so the behaviour is what we need; the
# stricter form is simply not expressible through mod_expires syntax. If you
# later want it exactly, that requires context{} blocks with extraHeaders.
#
# ---------------------------------------------------------------------------
# AFTER PASTING: Graceful Restart, then VERIFY. Do not assume it took.
#
#   bash scripts/verify-deploy.sh
#
# aaPanel can regenerate vhost.conf when you change site settings in the
# panel. Treat this file as the source of truth and re-run the verifier after
# any panel-side change to the site.
# ---------------------------------------------------------------------------

docRoot                   $VH_ROOT
vhDomain                  $VH_NAME
adminEmails               example@example.com
enableGzip                1
enableIpGeo               1

index  {
  useServer               0
  indexFiles index.html
}

errorlog /www/wwwlogs/$VH_NAME_ols.error_log {
  useServer               0
  logLevel                ERROR
  rollingSize             10M
}

accesslog /www/wwwlogs/$VH_NAME_ols.access_log {
  useServer               0
  logFormat               '%{X-Forwarded-For}i %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"'
  logHeaders              5
  rollingSize             10M
  keepDays                10  compressArchive         1
}


# >>> THE ONLY CHANGED BLOCK <<<
expires {
    enableExpires           1
    expiresByType           text/html=A0,text/plain=A0,application/json=A0,text/javascript=A86400,application/javascript=A86400,application/x-javascript=A86400,text/css=A86400,image/*=A2592000,font/*=A2592000,application/x-font-ttf=A2592000
}


# autoLoadHtaccess 1 is why the RewriteRules in public/.htaccess work even
# though the Header directives in the same file do not. Leave it on -- the
# rule returning a real 404 for missing /_next/ assets depends on it.
rewrite  {
  enable                  1
  autoLoadHtaccess        1
  include /www/server/panel/vhost/openlitespeed/proxy/app.rangook.ir/urlrewrite/*.conf
  include /www/server/panel/vhost/apache/redirect/app.rangook.ir/*.conf
  include /www/server/panel/vhost/openlitespeed/redirect/app.rangook.ir/*.conf
}
include /www/server/panel/vhost/openlitespeed/proxy/app.rangook.ir/*.conf

include /www/server/panel/vhost/openlitespeed/detail/ssl/app.rangook.ir.conf
include /www/server/panel/vhost/openlitespeed/detail/ssl/app.rangook.ir.conf
