This question has been flagged
10 Replies
11825 Views

I wanted one Odoo server to handle multiple low traffic sites on different domains.  Because multi-company is not well supported in the Community version (either it doesn't work or is not clearly documented), the best I could do was run Odoo against multiple databases, one for each domain.  I wanted the setup as simple as possible and with luck I found a way that doesn't require modifying source code (changing h.partition in "http.py") or setting up Apache as a proxy.

Here is how:

  1. Install Odoo as you normally would.

  2. Using iptables ("iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8069") point 8069 to 80 (if you are using UFW - make sure to open both ports! - "ufw allow 8069", and add the iptables line to /etc/rc.local to make it stick around after a reboot)

  3. Create the databases for your domains, but the database name *has* to take the form of "<domainname>_<TLD>", for example "yourdomain.com" should have a database named "yourdomain_com" with an underscore between the domain name and TLD.  If you try to use a dash instead of an underline, Odoo says it is not an allowed character, which must have been a change with v10 because everywhere else said use a dash.

  4. Then edit "/etc/odoo/odoo.conf" and add "dbfilter = %h" (I did it before the addons_path, but I don't think it matters)  There is endless documentation for using "%d" for subdomains, but very little for domains.

  5. Restart Odoo ("service odoo restart")

  6. Point your domain A records at Odoo and each site will then pick up it's respective database. 

You can actually do all this in reverse and it will still work, i.e. add dbfilter to odoo.conf, then visit each domain and create their respective databases (still appropriately named with underscores) for each domain.

A few caveats:

  1. You will notice that if you go to the database manager, it will only show you the database for the current domain, i.e. if you have two databases, one "myfirstdomain_com" and "mysecondomain_org", if you visit /web/database/manager from myfirstdomain.com, you will only see the myfirstdomain_com database.  The "mysecondomain_org" will be hidden.  You also can't fool Odoo by going to the database selector with an IP address, the only way to manage all the databases at once is to comment out the "dbfilter" code in odoo.conf.

  2. The domain must remove the "www" otherwise, it will fail.

  3. If you messed something up, you will get the database creation page popping back up.

It took me most of the day, but I figured it out with a lot of googling and just trying random things.  Someone else might as well save the hours if it takes me a half hour to document it.

Sean.

Avatar
Discard
Author Best Answer

(Since I can't delete this misthreaded answer) Odoo v10 does not allow dashes in the database name and why install any webserver when Odoo can do it by adding a single line to the configuration line.

Avatar
Discard

I did not test it yet, but you could also use underscores, IIRC.

But I would use %d instead of %h anyway. This works fine for the most cases because the www. gets stripped off.

Also it is not good practice to be forced to remove "www." from a FQDN. Keeping the "www." subdomain is mostly recommended for convenience and SEO reasons.

Best Answer

 Is it  possible to add domain filter on the odoo which running subdomain filter?.

Avatar
Discard
Best Answer

I've setup the environment using your suggestions and works on Odoo 11 too, also on windows:

http://robertozanardo.com/blog/2017/10/06/testing-odoo-11-port-80-with-multi-web-site-windows-server/

Avatar
Discard
Best Answer

I do not recommend your setup. A proper multi-domain deployment is a set-up with proxy server and SSL. How to do that is truly well documented, see for example here: https://www.odoo.com/forum/help-1/question/odoo-nginx-configuration-with-domain-name-and-db-filtering-for-multiple-domain-name-114775#answer-114777

Avatar
Discard
Author

I followed your links, and what you recommend (https://www.odoo.com/forum/help-1/question/odoo-8-0-apache2-how-to-configure-a-proxy-from-an-url-to-a-specific-database-in-a-multi-database-setup-110545#answer-110604) doesn't work with v10 because dashes are no longer allowed in the database name.

Why install any webserver when Odoo can do it by adding a single line to the configuration file.

As for SSL - use Cloudflare with a "Flexible" certificate or "Full" with a server side Let's Encrypt cert.

Generally, it is definitely not a general use case or recommended procedure to rely on a freemium service for vital deployments if it is not necessary. Additionally I do not consider it as an elegant solution in a multi-tenant multi-client environment, which it is usually the case when using dbfilter.

As this obviously still gets attention, I have to confirm my critic. A Flexible Cloudflare-Certificate is not a solution as stated by Cloudflare themselves: https://support.cloudflare.com/hc/en-us/articles/200170416-What-do-the-SSL-options-mean-

and if you want to use Full encryption on Cloudflare, you have to show how to install and deploy a certificate on your server using your approach. My recommendation remain: stay away from such advise, set up a proper reverse proxy, meanwhile this is very easy to install and it does not justify to use such flawed methods as presented here.