0
votes

I would like to publish two odoo instances using different paths, like mysite.com/odoo11 and mysite.com/odoo12. I am using odoo docker images and nginx:1.15.12-alpine docker image.

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name mysite.com;

        index index.php index.html index.htm;

        root /var/www/html;

#   ...ssl config...


#    location / {
#        proxy_set_header X-Real-IP  $remote_addr;
#        proxy_set_header X-Forwarded-For $remote_addr;
#        proxy_set_header X-Forwarded-Proto $scheme;
#        proxy_set_header Host $host;
#        proxy_pass http://odoo:8069;
#    }


    location /odoo {
        rewrite ^/odoo(.*) /$1 break;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $host;
        proxy_pass http://odoo:8069;
    }

    location ~* /web/static/ {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $host;
        proxy_pass http://odoo:8069;

    }

}

I started with just one odoo instance behind /odoo path. I have been looking around and found out that the way to do it is using the rewrite rule.

    location /odoo {
        rewrite ^/odoo(.*) /$1 break;

But when I use it in my config it does not redirect to the odoo docker image, it redirects to root folder instead. This is nginx log.

152.206.199.193 - - [03/Oct/2020:16:20:49 +0000] "GET /odoo HTTP/2.0" 200 84 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" "-"
2020/10/03 16:20:49 [error] 14#14: *6 open() "/var/www/html/web" failed (2: No such file or directory), client: 152.206.199.193, server: example.com, request: "GET /web HTTP/2.0", host: "example.com", referrer: "https://example.com/odoo"
152.206.199.193 - - [03/Oct/2020:16:20:49 +0000] "GET /web HTTP/2.0" 404 548 "https://example.com/odoo" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" "-"
2020/10/03 16:20:49 [error] 14#14: *6 open() "/var/www/html/favicon.ico" failed (2: No such file or directory), client: 152.206.199.193, server: example.com, request: "GET /favicon.ico HTTP/2.0", host: "example.com", referrer: "https://example.com/web"

I have tried proxy_redirect http://$host http://odoo:8069; instead of proxy_pass and changing the order of the rewrite rule. I still don't get the difference between the rewrite rule and proxy_redirect or proxy_pass so it would be nice to get some insight on that as well.

This is my first question on stackoverflow so thanks in advance.

1

1 Answers

1
votes

I don't think you will be successful at this.

The web page controllers, responsible to render wen pages, work based on a match with the URL path.

For example, mysite.com/web uses path /webfor the webclient controller. Rewriting it tomysite.com/odoo12/webuses path/odoo12/web`, and this won't trigger the webclient rendering controller.

Your best option is to use subdomains instead, such as odoo11.mysite.com and odoo12.mysite.com.

Odoo even has support for this. The dbfilter server option can dynamically filter the database to use to the one matching the subdomain name. See: https://www.odoo.com/documentation/12.0/setup/deploy.html#dbfilter