Running Odoo 18 behind Nginx reverse proxy is a production best practice that provides better performance, security, and flexibility. This guide will walk you through setting up Nginx as a reverse proxy for your Odoo 18 installation on Ubuntu 24.04 LTS.
Why Use Nginx with Odoo?
Using Nginx as a reverse proxy for Odoo offers several advantages:
- Better Performance: Nginx efficiently handles static files and caching
- Security: Hide Odoo's direct port access from the internet
- SSL Termination: Easier HTTPS configuration
- Load Balancing: Distribute traffic across multiple Odoo instances
- Additional Features: URL rewriting, compression, rate limiting
- Professional Setup: Access Odoo via domain name without port numbers
Prerequisites
Before starting, ensure you have:
- Odoo 18 installed and running (see our installation guide)
- Ubuntu 24.04 LTS server
- A domain name pointing to your server's IP
- Root or sudo access
- Odoo running on default port 8069
Step 1: Install Nginx
First, install Nginx on your Ubuntu 24.04 server:
sudo apt update sudo apt install nginx -y
Verify Nginx is running:
sudo systemctl status nginx
Step 2: Configure Odoo for Proxy Mode
Before configuring Nginx, update your Odoo configuration to work properly behind a proxy.
Edit your Odoo configuration file:
sudo nano /etc/odoo18/odoo.conf
Add or modify these settings:
[options] ; ... existing configuration ... ; Proxy mode proxy_mode = True ; Optional: Bind Odoo to localhost only (more secure) xmlrpc_interface = 127.0.0.1 netrpc_interface = 127.0.0.1
Restart Odoo to apply changes:
sudo systemctl restart odoo18
Step 3: Create Nginx Configuration for Odoo
Create a new Nginx configuration file:
sudo nano /etc/nginx/sites-available/odoo18
Add the following configuration:
# Odoo server upstream upstream odoo { server 127.0.0.1:8069; } upstream odoochat { server 127.0.0.1:8072; } # HTTP -> HTTPS redirect (will be used after SSL setup) server { listen 80; server_name your-domain.com; # Redirect all HTTP traffic to HTTPS # Uncomment the following line after SSL is configured # return 301 https://$server_name$request_uri; # For now, proxy to Odoo include /etc/nginx/snippets/odoo-proxy.conf; } # Main server block (will be HTTPS after SSL setup) # server { # listen 443 ssl http2; # server_name your-domain.com; # # # SSL configuration will go here # # include /etc/nginx/snippets/odoo-proxy.conf; # }
Step 4: Create Reusable Proxy Configuration
Create a snippet file for Odoo proxy settings:
sudo nano /etc/nginx/snippets/odoo-proxy.conf
Add the following content:
# 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; # Proxy settings proxy_connect_timeout 720s; proxy_send_timeout 720s; proxy_read_timeout 720s; proxy_buffering off; # File upload size client_max_body_size 50M; # Enable gzip compression gzip on; gzip_types text/css text/scss text/plain text/xml application/xml application/json application/javascript; gzip_vary on; # Logging access_log /var/log/nginx/odoo18-access.log; error_log /var/log/nginx/odoo18-error.log; # Redirect requests to Odoo backend location / { proxy_pass http://odoo; proxy_redirect off; } # Handle longpolling requests location /longpolling { proxy_pass http://odoochat; } # Cache static files location ~* /web/static/ { proxy_cache_valid 200 90m; proxy_buffering on; expires 864000; proxy_pass http://odoo; # Cache headers add_header Cache-Control "public, immutable"; add_header X-Static-Cache "HIT"; } # Common static file extensions location ~* \.(jpg|jpeg|png|gif|ico|css|js|pdf|doc|docx|xls|xlsx)$ { proxy_cache_valid 200 90m; proxy_buffering on; expires 30d; proxy_pass http://odoo; add_header Cache-Control "public"; } # Security headers add_header X-Frame-Options "SAMEORIGIN"; add_header X-Content-Type-Options "nosniff"; add_header X-XSS-Protection "1; mode=block";
Step 5: Enable the Nginx Site
Create a symbolic link to enable the site:
sudo ln -s /etc/nginx/sites-available/odoo18 /etc/nginx/sites-enabled/
Remove the default Nginx site if it exists:
sudo rm /etc/nginx/sites-enabled/default
Step 6: Test and Reload Nginx
Test the Nginx configuration:
sudo nginx -t
If the test passes, reload Nginx:
sudo systemctl reload nginx
Step 7: Configure Firewall
Update UFW firewall rules:
# Allow Nginx Full (HTTP and HTTPS) sudo ufw allow 'Nginx Full' # Remove direct Odoo port access (optional but recommended) sudo ufw delete allow 8069 sudo ufw delete allow 8072 # Reload firewall sudo ufw reload
Step 8: Test Your Configuration
Access your Odoo instance through Nginx:
http://your-domain.com
You should see your Odoo login page without the port number.
Advanced Nginx Configuration Options
1. Enable Nginx Caching
For better performance, create a cache directory:
sudo mkdir -p /var/cache/nginx/odoo sudo chown www-data:www-data /var/cache/nginx/odoo
Add cache configuration to your Nginx config:
# Add at the top of your configuration 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; # In your server block location ~* /web/static/ { proxy_cache odoo_cache; proxy_cache_valid 200 90m; proxy_cache_key "$scheme$request_method$host$request_uri"; add_header X-Cache-Status $upstream_cache_status; proxy_pass http://odoo; }
2. Rate Limiting
Protect against brute force attacks:
# Add at the top of your configuration limit_req_zone $binary_remote_addr zone=odoo_limit:10m rate=10r/s; # In your location blocks location /web/login { limit_req zone=odoo_limit burst=5 nodelay; proxy_pass http://odoo; }
3. Load Balancing Multiple Odoo Instances
If running multiple Odoo workers:
upstream odoo { least_conn; server 127.0.0.1:8069 weight=1; server 127.0.0.1:8070 weight=1; server 127.0.0.1:8071 weight=1; }
4. WebSocket Support
For real-time features, ensure WebSocket support:
location /websocket { proxy_pass http://odoochat; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }
Monitoring and Logs
View Nginx Access Logs
sudo tail -f /var/log/nginx/odoo18-access.log
View Nginx Error Logs
sudo tail -f /var/log/nginx/odoo18-error.log
Monitor Nginx Status
Enable Nginx status page:
server { listen 127.0.0.1:8080; server_name localhost; location /nginx_status { stub_status on; allow 127.0.0.1; deny all; } }
Troubleshooting Common Issues
Issue 1: 502 Bad Gateway
This usually means Odoo isn't running or Nginx can't connect:
# Check if Odoo is running sudo systemctl status odoo18 # Check if Odoo is listening on the correct port sudo netstat -tuln | grep 8069 # Check Nginx error logs sudo tail -20 /var/log/nginx/odoo18-error.log
Issue 2: 504 Gateway Timeout
Increase timeout values in your proxy configuration:
proxy_connect_timeout 3600s; proxy_send_timeout 3600s; proxy_read_timeout 3600s;
Issue 3: Static Files Not Loading
Ensure the static file location matches your Odoo installation:
# Find where Odoo static files are located sudo find /opt/odoo18 -name "static" -type d
Issue 4: Large File Upload Fails
Increase client body size in both Nginx and Odoo:
# In Nginx client_max_body_size 100M;
# In odoo.conf limit_request = 104857600
Performance Tuning
1. Enable HTTP/2
After SSL is configured, enable HTTP/2:
listen 443 ssl http2;
2. Optimize Worker Processes
In /etc/nginx/nginx.conf:
worker_processes auto; worker_connections 2048; use epoll; multi_accept on;
3. Enable Compression
gzip on; gzip_comp_level 6; gzip_min_length 1000; gzip_proxied any; gzip_vary on; gzip_types application/atom+xml application/javascript application/json application/x-javascript application/xml application/xml+rss text/css text/javascript text/plain text/xml;
Security Recommendations
1. Hide Nginx Version
In /etc/nginx/nginx.conf:
server_tokens off;
2. Implement Security Headers
Add to your server block:
# Security headers add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; add_header X-Content-Type-Options "nosniff" always; add_header X-Frame-Options "SAMEORIGIN" always; add_header X-XSS-Protection "1; mode=block" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Content-Security-Policy "default-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob: https:; font-src 'self' data: https:;" always;
3. Block Unwanted User Agents
# Block bad bots if ($http_user_agent ~* (crawler|spider|bot)) { return 403; }
Next Steps
Now that Nginx is configured as a reverse proxy for Odoo:
- Implement SSL/TLS: Secure your connection with HTTPS (see our SSL guide)
- Set up Monitoring: Use tools like Prometheus or Zabbix
- Configure Backups: Implement automated backup solutions
- Optimize Performance: Fine-tune based on your usage patterns
- Set up Fail2ban: Protect against brute force attacks
Conclusion
You've successfully configured Nginx as a reverse proxy for Odoo 18! This setup provides a professional, secure, and performant way to serve your Odoo instance. The configuration handles static files efficiently, supports WebSocket connections for real-time features, and prepares your setup for SSL implementation.
Remember to:
- Monitor your logs regularly
- Keep both Nginx and Odoo updated
- Test your configuration after any changes
- Implement SSL as soon as possible
In our next guide, we'll cover implementing SSL certificates to secure your Odoo installation with HTTPS.
Last updated: July 2025 | Compatible with Odoo 18 and Nginx on Ubuntu 24.04 LTS