Nginx as a reverse proxy is an essential solution for every production Odoo installation. It improves security and performance and enables SSL/TLS certificate handling. In this guide, we will show you how to properly configure nginx as a reverse proxy for Odoo.
Why use nginx as a reverse proxy for Odoo?
By default, Odoo runs on port 8069, which is not optimal for a production environment. Nginx as a reverse proxy offers a number of benefits:
- Security - hides the actual address and port of the Odoo server
- SSL/TLS - centralized management of certificates and encryption
- Performance - static content caching, gzip compression and HTTP/2 support
- Load balancing - the ability to distribute traffic across multiple instances
- Standard ports - access through ports 80 and 443
Installing nginx
Before configuring nginx as a reverse proxy for Odoo, you need to install it on your system. For Ubuntu/Debian systems, run:
sudo apt update
sudo apt install nginx -y
For CentOS/RHEL systems:
sudo yum install epel-release -y
sudo yum install nginx -y
After installation, start and enable nginx:
sudo systemctl start nginx
sudo systemctl enable nginx
Basic nginx configuration for Odoo
Create a new configuration file for Odoo in the nginx directory:
sudo nano /etc/nginx/sites-available/odoo
The basic reverse proxy configuration for Odoo looks as follows:
upstream odoo {
server 127.0.0.1:8069;
}
upstream odoochat {
server 127.0.0.1:8072;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name twoja-domena.pl;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
# Redirect to HTTPS
# return 301 https://$host$request_uri;
# Log files
access_log /var/log/nginx/odoo-access.log;
error_log /var/log/nginx/odoo-error.log;
# Proxy headers
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
# Handling long-lived connections (longpolling)
location /longpolling {
proxy_pass http://odoochat;
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
# Websocket handling for the messenger
location /websocket {
proxy_pass http://odoochat;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
# Main location
location / {
proxy_pass http://odoo;
proxy_redirect off;
}
# Cache for static files
location ~* /web/static/ {
proxy_buffering on;
expires 7d;
add_header Cache-Control 'public, max-age=604800, immutable';
proxy_pass http://odoo;
}
# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1000;
gzip_comp_level 5;
gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml+rss application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
gzip_disable 'msie6';
}
Explanation of key parameters
upstream odoo - defines the backend of the Odoo server running on port 8069. If you have changed the Odoo port, adjust this value accordingly.
upstream odoochat - handles websocket and longpolling for real-time features (messenger, notifications) on port 8072. From Odoo 11 onwards, gevent mode is used by default.
map $http_upgrade - ensures proper handling of the WebSocket protocol required by modern versions of Odoo.
proxy_read_timeout - an increased timeout for long-running operations in Odoo, such as generating reports or importing large files.
proxy_set_header - headers that pass client information to Odoo. The X-Forwarded-Proto header is particularly important for Odoo to work correctly behind a proxy.
Configuring the odoo.conf file to work with nginx
For Odoo to work properly with nginx as a reverse proxy, you need to adjust the odoo.conf configuration file. Add or modify the following parameters:
[options]
proxy_mode = True
xmlrpc_interface = 127.0.0.1
netrpc_interface = 127.0.0.1
workers = 4
longpolling_port = 8072
list_db = False
The proxy_mode = True parameter tells Odoo that it is running behind a reverse proxy and should trust the X-Forwarded-* headers.
The workers parameter enables multiprocessing mode - essential for production environments. Set the value to 2 x the number of CPU cores + 1.
The list_db = False parameter improves security by hiding the list of databases from unauthorized access.
Activating the nginx configuration
Create a symbolic link to the sites-enabled directory:
sudo ln -s /etc/nginx/sites-available/odoo /etc/nginx/sites-enabled/odoo
Check that the configuration is valid:
sudo nginx -t
If the test succeeds, reload nginx:
sudo systemctl reload nginx
HTTPS/SSL configuration
Configuring an encrypted connection is essential for a production environment. You can find a detailed guide in the article how to configure HTTPS/SSL for Odoo.
The basic HTTPS configuration looks as follows:
server {
listen 443 ssl http2;
server_name twoja-domena.pl;
ssl_certificate /etc/ssl/certs/odoo-cert.crt;
ssl_certificate_key /etc/ssl/private/odoo-key.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# HSTS
add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains' always;
# Remaining proxy configuration as above
# ...
}
Performance optimization
Increasing buffers
Add to the server configuration:
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
File size limit
If you plan to upload large files (e.g. attachments, documents):
client_max_body_size 100M;
Remember to also set the appropriate limit_memory_hard and limit_memory_soft parameters in the odoo.conf file.
Caching static content
For advanced caching, add a cache zone in the http section of the /etc/nginx/nginx.conf file:
proxy_cache_path /var/cache/nginx/odoo levels=1:2 keys_zone=odoo_cache:10m max_size=1g inactive=60m use_temp_path=off;
Then, in the static files location, add:
location ~* /web/static/ {
proxy_cache odoo_cache;
proxy_cache_valid 200 60m;
proxy_buffering on;
expires 7d;
add_header Cache-Control 'public, max-age=604800, immutable';
add_header X-Cache-Status $upstream_cache_status;
proxy_pass http://odoo;
}
Additional security measures
Hide the nginx version:
server_tokens off;
Add security headers:
add_header X-Frame-Options 'SAMEORIGIN' always;
add_header X-Content-Type-Options 'nosniff' always;
add_header X-XSS-Protection '1; mode=block' always;
add_header Referrer-Policy 'no-referrer-when-downgrade' always;
Optionally, you can add a Content Security Policy:
add_header Content-Security-Policy "default-src 'self' 'unsafe-inline' 'unsafe-eval' data: https:;" always;
Testing the configuration
After configuring nginx as a reverse proxy for Odoo, test the following:
- Access to Odoo through the standard port 80/443
- Longpolling functionality (messenger, notifications)
- File upload and download
- PDF report generation
- Check the nginx logs for errors:
sudo tail -f /var/log/nginx/odoo-error.log - Verify the HTTP headers in your browser (developer tools)
If Odoo runs as a systemd service, restart it after changing the configuration:
sudo systemctl restart odoo
Troubleshooting common problems
502 Bad Gateway
Check whether Odoo is running:
sudo systemctl status odoo
Verify the port in the upstream configuration. Check whether Odoo is listening on port 8069:
sudo netstat -tlnp | grep 8069
Check the Odoo logs for startup errors.
Longpolling problems
Make sure that port 8072 is open and Odoo is listening on it. Also check the websocket headers in the nginx configuration. In newer versions of Odoo (16+), longpolling may also work through the /websocket endpoint.
sudo netstat -tlnp | grep 8072
Verify that the workers parameter is set in odoo.conf (required for longpolling).
Slow page loading
Increase the timeout and buffer values. Enable gzip compression for more MIME types. Check that worker_class is set to gevent when using workers. Consider increasing the number of workers in the Odoo configuration.
Problems uploading large files
Make sure that the client_max_body_size parameter is set appropriately in nginx, as well as the memory parameters in odoo.conf. Check the timeouts - long uploads may require higher proxy_send_timeout values.
FAQ - Frequently asked questions
Can I use nginx with Odoo installed via Docker?
Yes, nginx works perfectly with Odoo running in a Docker container. In the upstream configuration, simply point to the appropriate port exposed by the container (mapped from the container's port 8069). You can find more information in the article about installing Odoo using Docker.
Does an nginx reverse proxy affect Odoo performance?
Quite the opposite - a properly configured nginx reverse proxy improves Odoo performance through static content caching, gzip compression, HTTP/2 support and efficient connection management. Nginx handles tens of thousands of concurrent connections while using minimal system resources. This is especially noticeable with a large number of users.
How do I configure nginx for multiple Odoo instances?
You can create separate server blocks for each Odoo instance, using different domains or subdomains. In the upstream section, define different ports for each instance (e.g. 8069, 8070, 8071) and the corresponding longpolling ports (8072, 8073, 8074). Each instance should have a separate configuration file in sites-available and a properly configured PostgreSQL database with the dbfilter parameter in odoo.conf to isolate the databases.
Do I need to use workers in Odoo behind nginx?
For production environments, definitely yes. The mode without workers (threaded) is suitable only for development. Workers enable parallel request processing and are required for longpolling functionality. Remember that along with workers, you must also configure longpolling_port.
Summary
Configuring nginx as a reverse proxy for Odoo is a key step in preparing your ERP system for production use. It improves security and performance and allows for professional management of HTTP/HTTPS traffic. Remember to regularly monitor the nginx logs, renew SSL certificates and adjust the configuration to the growing needs of your organization.
Need help configuring nginx for Odoo? The KK Innovations team specializes in implementing and optimizing Odoo systems. Contact us to get professional support with the installation, configuration and maintenance of your Odoo environment. We will provide a secure and efficient infrastructure for your business!