Odoo – super simple subdomain filtering with Cloudflare
5 March, 2021 by
Odoo – super simple subdomain filtering with Cloudflare
Administrator

Small introduction

Cloudflare is a great set of services for its community and their websites. It can provide you with high quality tools that any webmaster could ever wish for. Your sites are much safer with these services, and you can easily grasp what is really happening out there around your little Internet web corner.

You can get your free Cloudflare account in couple of minutes, and with it, you get your brand new name servers. All the benefits of moving your domains to Cloudflare is subject to the completely new post. Here, I just want to show three easy little steps on how to activate subdomain filtering to your odoo server (Ubuntu 14.04).

Subdomain filtering? Well, would you like that web address http://base.yourdomain.com/ automagically opens odoo instance and web site with database named base ? Thats it.
Did I mention that Cloudflare would also create ssl certificates for all your domains? For free? Yes and all your odoo sites will be ssl green and trusted worldwide.

1st step (location: odoo server)

First step is really just following this post -> http://netjunky.net/run-odoo-on-port-80-instead-of-8069/
It will reroute all incoming port 80 traffic to odoo default 8069.

2nd step (location: odoo server)

On our odoo server, we need to modify odoo daemon script. Usually, you want to setup your production odoo server with odoo daemon/service script. Script is more or less standard and usually placed here -> /etc/init.d/odoo-server (odoo-server name is optional).
Here is the part you need to modify:

2 Lines


# Additional options that are passed to the Daemon.
DAEMON_OPTS=”-c $CONFIGFILE”
And after the editing, DAEMON_OPTS line should look like this:
2 Lines


# Additional options that are passed to the Daemon.
DAEMON_OPTS=”-c $CONFIGFILE –db-filter=^%d$”
Save changes to the script and then restart service:
1 Lines


user@server:~$ sudo service odoo-server restart

3rd step (location: Cloudflare dashboard)
On your cloudflare dashboard select your domain, and then DNS tool for managing your

Domain Name System settings.

Add a new A record which points to your odoo server IP address -> example: A databasename points to 173.25.53.33
Open your browser with new address -> http://databasename.yourdomain.com/
Create new odoo database with name -> databasename (Note: it must be same as the subdomain name in the A record)

Repeate this step for every new subdomain you want to add.

Summary

And do you know what else? It works for all your different Cloudflare domains just as well, one odoo server with multiple domains and subdomains.
Obviously, you don’t want and can’t have two or more databases with the same name.

So if you need to have something like erp.domain1.com and erp.domain2.com on the same server, you will need to use slightly different regular expression for database filtering -> instead of ^%d$ you should use ^%h$ .

If we define domain like this -> hostname.domain.com, then regular expression ^%d$ will filter out string hostname. On the other hand regular expression ^%h$ will filter out string hostname.domain.com.
In short, if you decide to go with regular expression ^%h$ , database name in the 3rd step should be hostname-domain-com (we need to switch dots with dashes).
This is solution when you want to host larger number of databases on one odoo server and you need to have even more flexible domain name choices.
Enjoy your brand new odoo nicely named instances!
Hey what about SSL stuff?