Configure Nginx as a Reverse Proxy
Install Nginx and configure it to proxy HTTP and HTTPS traffic to Odoo, with WebSocket support, static file caching, and proper client IP forwarding.
Why Nginx?
Nginx sits between the public Internet and Odoo, providing several critical functions in a production deployment.
Install Nginx from the Ubuntu repositories.
sudo apt install -y nginx sudo systemctl enable nginx sudo systemctl start nginx
Nginx Configuration
Create a new virtual host configuration file for Odoo.
sudo nano /etc/nginx/sites-available/odoo
Paste the following complete configuration. Replace odoo.example.com with your actual domain.
upstream odoo {
server 127.0.0.1:8069;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name odoo.example.com www.odoo.example.com;
# Increase max upload size for attachments and backups
client_max_body_size 100M;
# Proxy timeouts for long-running operations
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
proxy_buffering off;
# Required headers so Odoo knows the real client details
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
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-Forwarded-Port $server_port;
# WebSocket support (required for Odoo bus and live chat)
location /websocket {
proxy_pass http://odoo;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
# Static files with caching
location /web/static/ {
proxy_pass http://odoo;
expires 10d;
proxy_cache_valid 200 90m;
}
# All other requests
location / {
proxy_pass http://odoo;
}
}Enable the site, test the configuration, and reload Nginx.
sudo ln -s /etc/nginx/sites-available/odoo /etc/nginx/sites-enabled/odoo # Disable the default site sudo rm -f /etc/nginx/sites-enabled/default sudo nginx -t sudo systemctl reload nginx
Disabling proxy buffering is important for Odoo. It ensures that responses are streamed to the client directly without waiting for the complete response to be buffered, which is critical for Odoo's real-time operations.
Verification
sudo nginx -t sudo systemctl status nginx --no-pager curl -I http://127.0.0.1
- ✓
nginx -treports syntax is ok and test is successful - ✓ Nginx is
active (running) - ✓
curlto port 80 returns an Odoo response or redirect - ✓ Default Nginx welcome page is disabled
Common Issues
| Problem | Cause | Resolution |
|---|---|---|
| Default Nginx welcome page | Default site still enabled | Remove /etc/nginx/sites-enabled/default and reload Nginx |
| 502 Bad Gateway | Odoo not running or wrong port | Verify systemctl status odoo and that Odoo is listening on port 8069 |
| WebSocket errors in Odoo | Missing Upgrade/Connection headers | Check the /websocket location block in the Nginx config |
| 413 Request Entity Too Large | client_max_body_size too small | Increase client_max_body_size in the Nginx config |
| Slow static assets | Caching not configured | Verify the /web/static/ location block with expires |
Odoo's built-in server is not designed to be exposed directly to the Internet. Always use Nginx as the entry point. Verify with sudo ss -tlnp | grep 8069 — the address should be 127.0.0.1:8069, not 0.0.0.0:8069.