{"article":{"slug":"local-mirror-for-freebsd-pkgbase","title":"Local Mirror for FreeBSD pkgbase","subtitle":null,"summary":"How to run a caching local mirror for FreeBSD pkgbase with Apache mod_cache and a reverse proxy, so deploying many systems or jails stops hammering the official mirrors.","content_type":"tutorial","language":"en","canonical_url":"https://blog.feld.me/posts/2026/11/local-mirror-for-freebsd-pkgbase/","author":{"name":"feld","url":null,"person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":"Makefile.feld","url":"https://blog.feld.me/","listing_slug":null,"listing":null},"topics":[{"name":"freebsd","slug":"freebsd","url":"https://listedarticles.com/topics/freebsd"},{"name":"devops","slug":"devops","url":"https://listedarticles.com/topics/devops"},{"name":"open-source","slug":"open-source","url":"https://listedarticles.com/topics/open-source"}],"about_listings":[],"cover_image_url":null,"license":"all-rights-reserved","word_count":513,"reading_minutes":2,"published_at":"2026-11-15T00:00:00.000Z","added_at":"2026-11-16T16:53:27.776Z","updated_at":"2026-11-16T16:53:27.776Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/local-mirror-for-freebsd-pkgbase","markdown_url":"https://listedarticles.com/articles/local-mirror-for-freebsd-pkgbase.md","example":false,"citation":"feld, Makefile.feld. \"Local Mirror for FreeBSD pkgbase.\" 15 Nov 2026. https://blog.feld.me/posts/2026/11/local-mirror-for-freebsd-pkgbase/ (all-rights-reserved)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://blog.feld.me/posts/2026/11/local-mirror-for-freebsd-pkgbase/"},"body_markdown":"# Local Mirror for FreeBSD pkgbase\n\nFreeBSD pkgbase finally brings the base OS to you as discrete packages\ninstead of monolithic tarball \"package sets\". However, if you want to\ndeploy a lot of systems or FreeBSD jails you will be hitting the\nofficial FreeBSD mirrors repeatedly which is not ideal. I have my own\ninternal package repository where I build packages from source, but I\ndon't do that for the base OS and do not intend to; there's really no\nchanges that I would want to make to the builds and having the base OS\nmatch the official upstream releases is important for ensuring their\nintegrity and being able to report any bugs you encounter.\n\nThis problem started to become very obvious to me when I was converting\nall of my FreeBSD jails to pkgbase deployments as the process wasn't\ncaching the packages anywhere locally and each conversion was hitting\nthe official mirrors over and over -- 36 times if I didn't intervene.\nThis is a lot of bandwidth wasted when I could just mirror it locally.\nSo I did, and this is how you can do it too.\n\n[## Apache](#apache \"Permalink to this section\")\n\nBelieve it or not, I'm still using Apache for a few things. If someone\nwants to share a similar configuration for Nginx I'll publish that as\nwell.\n\nThe one thing that bit me was that initially I pointed the reverse proxy\nconfiguration to `pkg.freebsd.org`. This won't work because that server\nwill redirect you to a CDN and Apache won't read through the redirect\nand cache it, so I pointed directly to the CDN right now. This\nabsolutely will change in the future when the CDN is completely hosted\nby the FreeBSD project again, but for now this is the requirement.\n\n```\n<IfModule !cache_module>\n  LoadModule cache_module libexec/apache24/mod_cache.so\n</IfModule>\n\n<IfModule !cache_disk_module>\n  LoadModule cache_disk_module libexec/apache24/mod_cache_disk.so\n</IfModule>\n\n<IfModule !ssl_module>\n  LoadModule ssl_module libexec/apache24/mod_ssl.so\n</IfModule>\n\n<IfModule !proxy_module>\n  LoadModule proxy_module libexec/apache24/mod_proxy.so\n</IfModule>\n\n<IfModule !proxy_http_module>\n  LoadModule proxy_http_module libexec/apache24/mod_proxy_http.so\n</IfModule>\n\nCacheRoot          /var/cache/apache-pkg\nCacheDirLevels     2\nCacheDirLength     1\n\nCacheIgnoreQueryString   On\nCacheIgnoreCacheControl  On\nCacheIgnoreNoLastMod     On\nCacheIgnoreHeaders       Set-Cookie\nCacheMaxFileSize         1073741824\nCacheMinFileSize         1024\nCacheDefaultExpire       31536000\nCacheDetailHeader        On\n\n<VirtualHost *:80>\n    ServerName pkg.feld.me\n    DocumentRoot /var/repos/\n\n    Alias /robots.txt /usr/local/www/apache24/data/robots.txt\n\n    # Where my local package repos are\n    <Directory /var/repos/>\n      AllowOverride none\n      Options Indexes FollowSymLinks\n      Require all granted\n    </Directory>\n\n    # pkgbase: reverse proxy, cache ONLY the immutable Hashed/blobs\n    SSLProxyEngine On\n    <LocationMatch \"^/pkgbase/[^/]+/[^/]+/Hashed/\">\n      CacheEnable disk\n    </LocationMatch>\n\n    CacheQuickHandler off\n\n    ProxyRequests     Off\n    ProxyPreserveHost Off\n    # Have to use the CDN directly to not chase redirects\n    ProxyPass         /pkgbase/ https://cloudfront.aws.pkgbase.freebsd.org/ connectiontimeout=30 timeout=600\n    ProxyPassReverse  /pkgbase/ https://cloudfront.aws.pkgbase.freebsd.org/\n\n    #    LogLevel cache:debug\n\n</VirtualHost>\n```\n\nNow on my servers I just change the repo config for the `FreeBSD-base` repo to:\n\n```\nFreeBSD-base: {\n  url: \"https://pkg.feld.me/pkgbase/${ABI}/base_release_${VERSION_MINOR}\",\n  mirror_type: \"none\",\n  enabled: yes\n}\n```\n\nSomething I should consider is publishing an SRV record that falls back to the official mirror if my webserver is down, but I haven't bothered with that yet.\n","body_html":"<h1 id=\"local-mirror-for-freebsd-pkgbase\">Local Mirror for FreeBSD pkgbase</h1>\n<p>FreeBSD pkgbase finally brings the base OS to you as discrete packages\ninstead of monolithic tarball &quot;package sets&quot;. However, if you want to\ndeploy a lot of systems or FreeBSD jails you will be hitting the\nofficial FreeBSD mirrors repeatedly which is not ideal. I have my own\ninternal package repository where I build packages from source, but I\ndon&#39;t do that for the base OS and do not intend to; there&#39;s really no\nchanges that I would want to make to the builds and having the base OS\nmatch the official upstream releases is important for ensuring their\nintegrity and being able to report any bugs you encounter.</p>\n<p>This problem started to become very obvious to me when I was converting\nall of my FreeBSD jails to pkgbase deployments as the process wasn&#39;t\ncaching the packages anywhere locally and each conversion was hitting\nthe official mirrors over and over -- 36 times if I didn&#39;t intervene.\nThis is a lot of bandwidth wasted when I could just mirror it locally.\nSo I did, and this is how you can do it too.</p>\n<p><a href=\"#apache\" title=\"Permalink to this section\">## Apache</a></p>\n<p>Believe it or not, I&#39;m still using Apache for a few things. If someone\nwants to share a similar configuration for Nginx I&#39;ll publish that as\nwell.</p>\n<p>The one thing that bit me was that initially I pointed the reverse proxy\nconfiguration to <code>pkg.freebsd.org</code>. This won&#39;t work because that server\nwill redirect you to a CDN and Apache won&#39;t read through the redirect\nand cache it, so I pointed directly to the CDN right now. This\nabsolutely will change in the future when the CDN is completely hosted\nby the FreeBSD project again, but for now this is the requirement.</p>\n<pre><code>&lt;IfModule !cache_module&gt;\n  LoadModule cache_module libexec/apache24/mod_cache.so\n&lt;/IfModule&gt;\n\n&lt;IfModule !cache_disk_module&gt;\n  LoadModule cache_disk_module libexec/apache24/mod_cache_disk.so\n&lt;/IfModule&gt;\n\n&lt;IfModule !ssl_module&gt;\n  LoadModule ssl_module libexec/apache24/mod_ssl.so\n&lt;/IfModule&gt;\n\n&lt;IfModule !proxy_module&gt;\n  LoadModule proxy_module libexec/apache24/mod_proxy.so\n&lt;/IfModule&gt;\n\n&lt;IfModule !proxy_http_module&gt;\n  LoadModule proxy_http_module libexec/apache24/mod_proxy_http.so\n&lt;/IfModule&gt;\n\nCacheRoot          /var/cache/apache-pkg\nCacheDirLevels     2\nCacheDirLength     1\n\nCacheIgnoreQueryString   On\nCacheIgnoreCacheControl  On\nCacheIgnoreNoLastMod     On\nCacheIgnoreHeaders       Set-Cookie\nCacheMaxFileSize         1073741824\nCacheMinFileSize         1024\nCacheDefaultExpire       31536000\nCacheDetailHeader        On\n\n&lt;VirtualHost *:80&gt;\n    ServerName pkg.feld.me\n    DocumentRoot /var/repos/\n\n    Alias /robots.txt /usr/local/www/apache24/data/robots.txt\n\n    # Where my local package repos are\n    &lt;Directory /var/repos/&gt;\n      AllowOverride none\n      Options Indexes FollowSymLinks\n      Require all granted\n    &lt;/Directory&gt;\n\n    # pkgbase: reverse proxy, cache ONLY the immutable Hashed/blobs\n    SSLProxyEngine On\n    &lt;LocationMatch &quot;^/pkgbase/[^/]+/[^/]+/Hashed/&quot;&gt;\n      CacheEnable disk\n    &lt;/LocationMatch&gt;\n\n    CacheQuickHandler off\n\n    ProxyRequests     Off\n    ProxyPreserveHost Off\n    # Have to use the CDN directly to not chase redirects\n    ProxyPass         /pkgbase/ https://cloudfront.aws.pkgbase.freebsd.org/ connectiontimeout=30 timeout=600\n    ProxyPassReverse  /pkgbase/ https://cloudfront.aws.pkgbase.freebsd.org/\n\n    #    LogLevel cache:debug\n\n&lt;/VirtualHost&gt;</code></pre>\n<p>Now on my servers I just change the repo config for the <code>FreeBSD-base</code> repo to:</p>\n<pre><code>FreeBSD-base: {\n  url: &quot;https://pkg.feld.me/pkgbase/${ABI}/base_release_${VERSION_MINOR}&quot;,\n  mirror_type: &quot;none&quot;,\n  enabled: yes\n}</code></pre>\n<p>Something I should consider is publishing an SRV record that falls back to the official mirror if my webserver is down, but I haven&#39;t bothered with that yet.</p>","headings":[{"level":1,"text":"Local Mirror for FreeBSD pkgbase","id":"local-mirror-for-freebsd-pkgbase"}]}}