Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nj-dream opened this issue Feb 18, 2023 · 3 comments

Comments

@nj-dream
Copy link

nj-dream commented Feb 18, 2023

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
Copy link

chris001 commented May 7, 2023

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
Copy link
Author

nj-dream commented May 9, 2023

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
Copy link

chris001 commented May 9, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants