Yenthe666 / InstallScript

Odoo install script
MIT License
1.21k stars 1.54k forks source link

I have a question about supporting multiple domains with multiple databases. #385

Open nj-dream opened 1 year ago

nj-dream commented 1 year ago

I have installed an Odoo16 instance using your script. The domain name is a.mydomain.com and the database is 'a'. Now I want to add another domain name, b.mydomain.com, with a separate database 'b'. I would like to use different subdomains to access different Odoo instances with different databases.

My server environment is Ubuntu 22.04 with SSL enabled. I first copied the nginx configuration file for a.mydomain.com and replaced all instances of a.mydomain.com with b.mydomain.com in the new configuration file. Then I ran 'sudo ln -s /etc/nginx/sites-available/b.mydomain.com /etc/nginx/sites-enabled/b.mydomain.com' and used 'sudo certbot --nginx -d b.mydomain.com --noninteractive --agree-tos --email admin@mydomain.com --redirect' to create an SSL certificate.

I then used Odoo's database management function to create a new database named 'b'. Next, I modified the 'odoo.conf' configuration file by adding 'dbfilter = ^%d$'. Finally, I restarted Odoo and nginx.

When I visit a.mydomain.com, I see the Odoo login page for the 'b' database, visit a.mydomain.com and when I visit b.mydomain.com, I see the Odoo database selection page. visit b.mydomain.com

What did I do wrong and how can I access the correct Odoo database based on the subdomain name? Thank you!"

chris001 commented 1 year ago

Hello,

  1. Carefully use the dbfilter parameter in the odoo .conf file. You have 2 options:

A. %d: Odoo extracts the subdomain of a hostname except "www". Examples: "www.subdomain.domain.tld" results in Odoo looking for the database name "subdomain". "subdomain.domain.tld" results in Odoo looking for the same database name "subdomain". "www.domain.tld" results in Odoo looking for the database name "domain".

B. %h: Odoo takes the full domain name. Examples: "www.subdomain.domain.tld" results in Odoo looking for the database name "www-subdomain-domain-tld". "subdomain.domain.tld" results in Odoo looking for the database name "subdomain-domain-tld", and so on.

%d or %h are regex expressions. In my setup I use dbfilter = ^%d$.

  1. In your Nginx vhost definition, proxy to the IP address and port of your Odoo server and forward the request headers:
    location / {
    proxy_pass http://my_odoo_IP_address:port;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

If it isn't possible to match database names from the host/domain name, you can use the module db_filter_from_header to do this for you, without you having to add any of the above configuration lines into the odoo .conf file and nginx .conf file.

nj-dream commented 1 year ago

Thank you so much for your talking the time to respond to my question. Your answer was incredibly helpful and I really appreciate it.

chris001 commented 1 year ago

@nj-dream Happy to solve this issue. In your case, what exactly was the precise cause of your issue? Which solution did you use?