How to serve Odoo static files and attachments from Nginx
Nginx can serve some of this file traffic directly, but attachment downloads still depend on Odoo's access checks. On a self-hosted Odoo server, the Python workers handle every request, including requests for images, JavaScript and CSS files and attachment downloads. Odoo ships its web client assets and the static folders of each module, and it stores uploaded attachments in a filestore on disk, organized by database. Static files are public application assets, so a web server can return them without involving Odoo. Attachments are different. Each one belongs to a record that a user may or may not be allowed to read, so Odoo has to decide access before any file leaves the server. Offloading is therefore a split: Nginx takes the static assets, and Odoo keeps control of attachment permissions while the file transfer itself can be handed to Nginx.
File traffic competes with page requests because every worker is a fixed unit of concurrency. A single slow download or a burst of image requests when a user opens a large list view can hold a worker that would otherwise answer a form save or a report request. Teams usually notice this as slow screens during file-heavy work, not as a server error. Offloading is worth planning when attachment volumes grow large, when many users share one server, or when pages slow down during document-heavy work such as invoice or receipt uploads. Before changing anything, measure how much of the request load is static or attachment traffic in the web server access log, and check which worker is busy during the slow periods.
The exact behavior depends on the Odoo version and edition, so confirm the location blocks, the --x-sendfile flag and the X-Accel header names against the Odoo documentation for your release before you copy any configuration. Also confirm how your edition serves its web assets, since cache headers and Content-Security-Policy settings for images can differ between versions. Treat the filestore path, its ownership and its backup as part of the same change, because Nginx must be able to read files that Odoo writes. Test attachment downloads with a user who lacks access to the record, not only with an administrator, so you can confirm that the access check still runs.
Which Odoo file paths to offload and which to keep in Odoo
This table compares the four file paths a self-hosted Odoo install serves: module static assets, filestore attachments, cache headers and image Content-Security-Policy. Read each row for who decides access and what Nginx must do, then choose the paths your traffic and access rules justify moving off the workers.
| Path | What it serves and who decides access | What Nginx needs and when it fits |
|---|---|---|
| Module static folders | Static assets shipped with addons, such as JavaScript, CSS and images. Odoo serves these without a per-user record check. | A location block that maps the static path to the addon directories. Fits well when assets are public to any logged-in or anonymous visitor. |
| Filestore attachments via X-Accel | Attachments stored in the filestore. Odoo checks the user's access rights first, then hands the file to Nginx. | Requires the --x-sendfile flag, an internal location matching the filestore path and an X-Accel-Redirect response. Fits when access checks must stay in Odoo. |
| Direct filestore serving without X-Accel | Files read straight from disk by Nginx. Nginx cannot apply Odoo's record rules. | Simpler to configure but exposes files to any request that reaches the path. Usually does not fit where attachments carry business or personal data. |
| Cache headers on static responses | Browser and proxy caching for assets that change only on upgrade or deployment. | Expires and Cache-Control directives in the static location. Confirm asset versioning in your Odoo version before setting long cache lifetimes. |
| Content-Security-Policy for images | Policy headers applied to image and attachment responses, limiting what the browser may load or run. | Add-header directives in the Nginx location. Test in the browser, because a strict policy can break previews or embedded PDFs. |
| Dynamic pages and API calls | Views, reports and JSON calls that depend on the session and record rules. | Keep these on Odoo workers and proxy them. Offloading does not reduce this load, and caching can expose user-specific data. |
| Attachments with public access settings | Files Odoo marks as public, where access is not tied to a single user. | Can be served with fewer checks, but confirm each attachment's access setting before exposing the path. Fits only for truly public content. |
How an attachment request moves between Nginx and Odoo
The diagram starts with a browser asking for an attachment at the public edge, where Nginx receives the request and forwards it to an Odoo worker. The worker checks that the signed-in user can read the record. If access passes, it returns an internal redirect header such as X-Accel-Redirect, and Nginx reads the file from the filestore directory and sends it to the browser. Static assets skip the worker entirely: Nginx serves them straight from the module static folder. Confirm that the filestore path is never exposed as a public location.
Attachment requests pass an Odoo access check, while static assets bypass workers.
How X-Accel hands filestore downloads to Nginx after Odoo checks access
Odoo keeps the access decision. An attachment request still runs through Odoo's access checks, so a user who cannot read the record that owns an attachment still cannot download it. What X-Accel changes is who sends the bytes. After Odoo approves the request, it returns an empty response with an X-Accel-Redirect header that names an internal path, and Nginx reads the file from disk and streams it to the client. Clients never see the filestore path, and Odoo workers no longer spend their time streaming large files. The security boundary stays in Odoo, so the Nginx side must not add a second, looser way to reach the same files.
Enabling the handoff takes two matching pieces. On the Odoo side, start the server with the --x-sendfile command line flag or set the equivalent x_sendfile key in odoo.conf. Confirm the exact flag and key name in the Odoo documentation for the version you run, because the configuration reference changes between releases. On the Nginx side, add an internal location that aliases the filestore directory. The internal directive makes Nginx answer direct client requests to that path with not found, so only redirects issued by Odoo can reach the files. The filestore path must match on both sides: the directory Odoo writes attachments to under its data directory, including the per-database subfolder, must be the same tree the Nginx alias points to. Confirm the layout on your own server before you write the location block.
Test the handoff before go-live with two users. Sign in as a user who has no rights to a record, open an attachment from that record, and confirm Odoo refuses the request. Then sign in as a user who has rights and confirm the download works. Request the internal location URL directly from a browser and confirm the client receives a not found response. The most common failure is a path mismatch, which breaks downloads while the Odoo log looks clean. Also confirm that the Nginx worker user can read the filestore files and that the database name in the path matches the database the user is signed into. Record these checks in your go-live plan so they are repeated after each upgrade or proxy change.
Nginx static files setup: locations, X-Accel and checks
This sequence moves Odoo static assets and filestore attachments off the Odoo workers, with Nginx serving them only after Odoo has checked access, and ends with tests that prove both paths work.
Confirm version, edition and install method
Record the Odoo major version, whether you run Community or Enterprise, and whether you installed from packages, source, or the official Docker image. The file paths and the restart command in later steps depend on this. Ask your team to confirm the version against the support dates in Odoo's documentation, because an end-of-support release will not receive security patches. The step is done when the version, edition and install method are written in your change record and match what the server reports.
Locate the filestore and module static folders
On the Odoo host, find the data directory set in odoo.conf and the filestore folder for each database inside it. Then locate the static folders of the installed addons, which sit inside each addon directory. For Docker installs, these paths live inside the container volumes, so check the volume mounts first. Confirm that the Nginx service account can read these folders but that the folders are not inside any path Nginx already serves publicly. The step is done when you have a list of absolute paths and a read test from the Nginx user succeeds.
Add an internal location for the filestore
Add an Nginx location block for the filestore path that is marked as internal, so clients cannot request it by typing a URL. Map it to the filestore directory and set the cache headers you have agreed for attachments. Keep the existing location blocks for the websocket and proxy_mode settings untouched, because the sibling Nginx setup page covers them. The step is done when
nginx -treports a valid configuration and a direct request to the internal path from outside the server returns a denial.Add a public location for module static files
Add a location block for the /web/static path so Nginx serves module assets directly from disk instead of passing them to the Odoo workers. Set a long expiry only for versioned asset bundles and a shorter one for everything else. The step is done when
nginx -tpasses and a request for a known static file, such as a CSS file from the web module, returns a 200 status with the expected content type and no login.Enable x-sendfile in Odoo and restart the service
Start Odoo with the --x-sendfile flag, or set the equivalent option in odoo.conf, so Odoo returns an X-Accel-Redirect header instead of streaming the file itself. Odoo still checks the user's access rights before sending that header, so this does not replace permission checks. Restart the Odoo service with your usual method, such as systemd or a container restart. The step is done when the service starts without errors in its log and the flag appears in the running process or configuration.
Reload Nginx and confirm the redirect
Reload Nginx so the new locations take effect, then confirm that Odoo passes the X-Accel-Redirect header to Nginx for a filestore attachment. A check with an authenticated request that returns the file through the public URL is enough, and you can look for the header in the response. Watch the Nginx error log for permission or path errors on the first request. The step is done when the attachment downloads for an authorized user and the log shows no file access errors.
Test anonymous and unauthorized access
Request a static asset with no session cookie and confirm it loads. Then request an attachment URL with no session, and then as a user who has no access to the record that owns it. Odoo should deny both attachment requests, typically with a 403 or a redirect to the login page, and Nginx should never return the file. Use the browser's network panel to confirm which requests were served by Nginx and which reached Odoo. The step is done when the denial responses match your access model and no attachment bytes are returned without a permission check.
Verify the file path in the browser network panel
Open an authorized attachment in a browser, open the network panel, and check the response for the file. The response should come from the same host and carry the cache headers you set, and the timing should show that the Odoo workers were not used for the bytes. Repeat the test on one static asset and one large attachment. Record the results and keep the Nginx configuration in version control so future changes can be reviewed. The step is done when both file types show the expected headers and the test results are filed with the change record.
Cache headers and Content-Security-Policy for images
Cache headers decide what browsers and intermediate proxies keep after Nginx serves a file, so they matter most for the two kinds of traffic this topic moves off the Odoo workers. Module static files, such as icons and bundled assets, can usually be cached for a long time because their URLs change when the content changes. Odoo builds static paths with a version component, so a new release produces new URLs and stale copies stop being requested. Filestore attachments behave differently. A user can replace a file at the same record, and the URL may stay the same, so a long Cache-Control lifetime can leave people looking at an old version after an update. Set short or private lifetimes for attachment responses unless your review shows the URLs are unique per file version. Confirm the exact values with your security team and check them against your own pages, since the right choice depends on how your users replace and share files.
Content-Security-Policy restricts where a page or response may load resources from, including images, frames and other embedded content. Its image directive controls which image sources the browser accepts. A policy written for the web pages can block images, previews or embedded documents that come from a different origin, such as a CDN, a storage endpoint or a separate host used for attachments. The result is often a broken preview that looks like an Odoo bug. Review every origin your users see in the browser console and in the attachment preview flow before you tighten the header. Ask your security team to agree the directives in writing, and test the header in a staging copy with real attachment types and a realistic set of user roles before production. Keep the rollback steps for the Nginx configuration ready, because a header change applies to every response it covers.
Security checks for Odoo attachments served by Nginx
Once Nginx serves files directly, the web server becomes part of Odoo's access control. The cards below cover the places where a file can leak: the filestore path itself, location blocks that skip Odoo's checks, path handling, stale caches, image rendering and the logs that show what was served.
Filestore exposed to direct requests
The filestore holds every attachment Odoo stores, and it sits on disk under the data directory. If an Nginx location or alias maps a URL prefix onto that directory, anyone who guesses or learns a file path can fetch it without signing in. Run a request test with no session cookie against a known attachment path and confirm a 403 or 404. Ask the team that owns the Nginx configuration to confirm that no location block points at the data directory.
Odoo on-premise docsLocation blocks that bypass access checks
Static folder locations for module assets are safe to serve directly, but a broad regex or a copied block can also match attachment routes and skip the X-Accel handoff. The result is a file served to any caller once Nginx matches the path. Review every location block against the routes Odoo uses for attachments and confirm each one that serves files has an explicit, narrow match. Assign this review to the platform engineer who owns the reverse proxy.
Path handling that escapes the filestore
The X-Accel-Redirect value that Odoo returns is a path Nginx trusts. If an internal location uses an alias without a trailing slash, or if path segments are not normalized, a crafted value can point outside the filestore. Test with encoded traversal sequences such as .. and double-encoded slashes, and confirm each returns an error rather than a file. The security engineer should own this test and repeat it after every Nginx change.
Cached responses outliving permissions
Proxy caches and browser caches can keep a copy of an attachment after a user loses access to the record or the record is deleted. Long Cache-Control lifetimes make this worse for private documents. Decide which content types may be cached publicly, which must be private with no-store, and document the rule. Check that a response for a restricted record carries private or no-store, and ask the operations lead to confirm that no shared proxy cache covers attachment routes.
Content-Security-Policy gaps for uploaded images
Users can upload images and some file types that a browser may render as active content. Without a Content-Security-Policy header and a X-Content-Type-Options header on attachment responses, a crafted file can run script in the Odoo origin. Check the response headers for an uploaded SVG or HTML file, confirm the policy blocks inline script, and confirm the browser does not sniff the type. The application security lead should set the policy and test it with the file types your users actually upload.
Logging of served and denied requests
Without access logs for attachment routes, a data exposure cannot be traced to a user, a time or a file. Log the status code, the requested path, the user session identifier where Nginx can see it and the response size for attachment locations, and send these logs to the team's central log store. Confirm that a denied request appears in the log with a 403 status. The operations team should own log retention and set it to match the organization's records policy.
Questions teams ask before serving Odoo attachments from Nginx
Can our team set up Nginx to serve Odoo attachments without outside help?
Yes, if your team already runs Nginx in front of Odoo and is comfortable editing server configuration, restarting services and reading logs. The change itself is small: a location block for static assets and an internal location that Nginx uses to send files after Odoo has checked access. The effort sits in the testing. Your team needs to prove that permissions still hold for private records, portal users and public website files, and that a failed check never exposes a file. If nobody on the team has tested access rules end to end, a partner or a second reviewer is worth considering. See the Odoo behind Nginx with SSL, proxy mode and websockets setup guide for the baseline this change builds on.
What do we need to provide before the work starts?
Plan to provide four things: shell access to the Odoo and Nginx servers or a change window with someone who has it, the exact Odoo version and deployment method, a recent staging copy of the production database and filestore, and a written test plan. The test plan should list who must see which attachments, which must not, and which website assets must load for anonymous visitors. Confirm the filestore path and the Nginx version as well, since both affect the configuration. Without a staging copy, the change cannot be checked against real attachment records safely.
How long does this take, and what makes it longer?
The duration depends on the number of deployment environments, how many access rules must be tested, and how much of the current Nginx configuration is custom. A single server with standard Odoo records and a short test list is a small job. Duration grows with multiple databases on one host, custom modules that store files in unusual places, portal and website access that differs by company, and any need to coordinate a maintenance window. Ask any provider to break the timeline into configuration, access testing, staging sign-off and production rollout, and to state which of those steps they expect your team to own.
Does this work the same way on Odoo Community and Enterprise?
The Nginx pattern applies to the server side of both editions, since the attachment and static file paths are served by Odoo itself. The practical differences come from the edition's features and support. Enterprise deployments usually run on a subscription with the Enterprise addons placed alongside Community code, so the Nginx location rules should be checked against the addon paths in use. Community deployments carry the same configuration duty but rely on a self-maintained upgrade path. Confirm your edition and addon paths with your Odoo contract and your own server layout before copying any configuration.
What does this cost, and what drives the price?
Cost comes from the labor to change, test and document the setup, plus any Nginx or infrastructure work needed to support it. Your internal team's time is a cost even when no invoice is issued. The main drivers are the number of environments, the number of access rules to verify, the complexity of your current proxy configuration, and whether you need a repeatable runbook for future upgrades. Recurring costs are small in comparison, mostly the time to review configuration changes after each Odoo upgrade. Ask any quote to itemize the scope, the test matrix, the deliverables and the retest effort, and to state what is excluded.
Does this approach work in Docker and on Odoo.sh?
It works in Docker when Nginx can reach the filestore path that the Odoo container writes to, usually through a shared volume or a bind mount, and when the internal location maps to that same path. On Odoo.sh the hosting platform controls the web tier, so you cannot place your own Nginx rules in front of the platform in the same way. Check what Odoo.sh exposes for static and attachment handling before planning the change, and treat it as a separate design question. The Odoo on-premise documentation is the natural starting point for self-hosted deployments.
What should we check after an Odoo upgrade?
Treat every Odoo upgrade as a reason to retest the attachment path. Upgrades can change how assets are named, where static files are served from, and how attachment access is checked. After the upgrade, confirm that the static location still matches the asset URLs in the new version, that private attachments still return an access denial for users who should not see them, and that cache headers and Content-Security-Policy settings still apply to images. Keep the test list from the original project and run it on the upgraded staging copy before production. The Odoo upgrade documentation describes the upgrade path that should set the order of these checks.
Limits to confirm before you serve Odoo attachments from Nginx
The Nginx pattern for static files and attachments depends on the Odoo version, the install method, the storage layout and the Nginx build in use. Each of the items below is something to confirm in your own environment rather than assume from a tutorial. Together they decide whether the setup is worth building and how long it will stay valid.
Flag and config keys for your version
The --x-sendfile flag and the related Nginx and Odoo settings depend on the exact Odoo release you run. Read the configuration reference for that version, and confirm the flag name, the header Odoo emits and the expected internal location path before copying any snippet. A setting that worked on one major version can change or disappear on the next, so write down the version you verified against.
Whether your install method lets you change Nginx
Packages and source installs usually give your team control of the Nginx site configuration. Docker deployments depend on how the reverse proxy container is built and mounted, and Odoo.sh manages the web tier for you, so you may not be able to add these locations at all. Confirm who owns the Nginx layer before you design the file routing, because that decides whether this is a configuration task or a platform question.
Filestore layout on your storage
Odoo stores attachment content in a filestore directory, separate from the PostgreSQL database, and Nginx can only serve it if the path it reads matches the path Odoo writes. Check where the filestore lives on your chosen storage, who owns it, and whether it is on a network volume or local disk. Mounted or shared storage can also change file permissions and latency, which affects the internal location you configure.
How upgrades change file handling
A major upgrade can change how Odoo sets headers, names attachments or routes file requests, so a working Nginx block may need retesting after each version change. Plan a test of attachment downloads, module assets and image rendering on a staging copy of the database and filestore before every upgrade. Record the Nginx configuration with the Odoo release it was tested against.
Nginx build and internal location support
The internal location pattern relies on Nginx features and a build that includes the modules you need, including the module used for X-Accel handling in some setups. Confirm the Nginx version and build flags on your servers, and check that the directives you plan to use are available there. Test the internal redirect with a real attachment request, because a configuration that passes a syntax check may still fail at runtime.
Support window and version choice
Standard support sets how long you receive security updates and bug fixes, so it should drive the version you build on. Odoo 19.0 standard support runs until September 2028, and Odoo 18.0 runs until September 2027, while Odoo 17.0 standard support has already ended. Choose a version whose window covers your planned go-live and upgrade cadence, and confirm the current dates with Odoo before you commit.
Odoo support datesHow DeployOpen scopes and delivers Odoo file serving
DeployOpen plans Nginx file serving for Odoo as part of the wider server build, so static assets, filestore attachments and access checks are designed together. We scope the work in writing, build it in your own infrastructure, and hand over the configuration with the evidence your security and operations teams need to review it.
How we scope
- We confirm your Odoo edition, hosting type and version, since file serving behavior depends on the deployment path.
- We list which locations, filestore paths and attachment types are in scope, and which access rules Odoo must still enforce.
- Engagements are fixed-scope, with deliverables and timelines agreed in writing before any configuration work starts.
How we build
- We configure Nginx locations for module static folders and test them behind your existing reverse proxy and SSL setup.
- We enable the X-Accel path for filestore attachments only after confirming Odoo's access checks run first, then test denied and allowed requests.
- We set cache headers and a Content-Security-Policy for images, and verify them in a staging copy before production.
How we hand over
- You receive the Nginx configuration, the Odoo settings changed, and a record of each test run with its expected and actual results.
- We document the file storage paths, backup dependencies and the steps to roll back to direct Odoo serving if needed.
- Your security and compliance team gets an evidence pack that they can review against their own access and logging requirements.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers, so configuration keeps pace with Odoo version changes.
- We retest file access rules after each Odoo upgrade or proxy change, since upgrades can alter static asset paths.
- We confirm with you which support windows apply to your Odoo version before planning changes to the file serving setup.

