How to use NGINX to reverse proxy Odoo

Routing the HTTP and long-polling ports

Reverse proxy Odoo with NGINX

Here's a tutorial on how to reverse proxy Odoo using NGINX.


# Upstreams for the http and longpolling ports # these (odoosrv and odoolong) vars will be used in other places in the conf file # refer to: # http://nginx.org/en/docs/http/load_balancing.html

upstream odoosrv {
    server 127.0.0.1:8069 weight=1 fail_timeout=0;
}
upstream odoolong {
    server 127.0.0.1:8072 weight=1 fail_timeout=0;
}
server {
listen 443 ssl;
server_name www.example.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
proxy_buffers 16 64k;
proxy_buffer_size 128k;
client_max_body_size 4M;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types
text/css
text/javascript
text/xml
text/plain
image/bmp
image/gif
image/jpeg
image/jpg
  image/png
  image/svg+xml
  image/x-icon
  application/javascript
  application/json
  application/rss+xml
  application/vnd.ms-fontobject
  application/x-font-ttf
  application/x-javascript
  application/xml
  application/xml+rss;

location ~^/web/database {
rewrite ^/web/database(.*) http:// permanent;
}
location ~* ^/([^/]+/static/|web/(css|js)/|web/image/|web/content/|website/image/) {
proxy_cache_valid 200 60m;
proxy_buffering on;
expires 30d;
proxy_pass http://odoosrv;
}
location / {
proxy_connect_timeout 360s;
proxy_send_timeout 360s;
proxy_read_timeout 360s;
proxy_pass http://odoosrv;
proxy_set_header Host $host;
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_next_upstream error timeout invalid_header http_500 http_502 http_503;
proxy_redirect off;
}
location /longpolling {
proxy_pass http://odoolong;
proxy_set_header Host $host;
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_next_upstream error timeout invalid_header http_500 http_502 http_503;
proxy_redirect off;
}
ssl_certificate /certs/fullchain.pem;
ssl_certificate_key /certs/privkey.pem;
include /certs/options-ssl-nginx.conf;
ssl_dhparam /certs/ssl-dhparams.pem; }