Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

[Odoo 8.0 - apache2] How to configure a proxy from an url to a specific database, in a multi-database setup ?

By
PY
on 11/8/16, 3:42 AM 304 views

Hi !


Given the standard multi-db configuration:

# wildcard proxy for odoo:
# one subdomain -> one database

<VirtualHost *:80>
 ServerName mydomain.fr
 ServerAlias *.mydomain.fr

 ErrorLog /var/log/odoo/odoo-error.log
 CustomLog /var/log/odoo/odoo-access.log combined
 LogLevel warn

 <Proxy *>
  Order deny,allow
  Allow from all
 </Proxy>

 ProxyRequests Off
 ProxyPass / http://mydomain.fr:8089/
 ProxyPassReverse / http://mydomain.fr:8089/

 ProxyVia On
</VirtualHost>

So I already know how to serve database 'foo' with url http://foo.mydomain.com.

In my Odoo config, the dbfilter is set to ^%d$.

How one would add a domain which point to a specific database ?

Example:

  • user access to http://bar.com/web/login

  • apache proxies to http://quz.mydomain.fr/web/login

  • then the config already in place do its job like for other databases: proxy to http://mydomain.fr:8089/ with previous url given to Odoo, so that it serves the db matching the subdomain (here database_of_another_domain)

0
PY
On 11/14/16, 3:55 AM

Finally, I came up with this:

################
# welcome page #
################

<VirtualHost *:80>
    ServerName mydomain.fr
    ServerAlias www.mydomain.fr
    DocumentRoot /var/www/odoo
</VirtualHost>


#################
# wilcard proxy #
#################

<VirtualHost *:80>
    ServerName mydomain.fr
    ServerAlias *.mydomain.fr

    ErrorLog /var/log/odoo/odoo-error.log
    CustomLog /var/log/odoo/odoo-access.log combined
    LogLevel warn

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / http://mydomain.fr:8089/
    ProxyPassReverse / http://mydomain.fr:8089/

    ProxyVia On
</VirtualHost>


##################
# customer proxy #
##################

<VirtualHost *:80>
    ServerName other-domain.com
    ServerAlias www.other-domain.com

    ProxyRequests Off
    ProxyPass / http://other-domain.mydomain.fr/
    ProxyPassReverse / http://other-domain.mydomain.fr/

    ProxyVia On
</VirtualHost>


################
# restrictions #
################

<Location /web/database>
    Order deny,allow
    Deny from all
    Allow from 1.2.3.4
    Allow from 5.6.7.8
</Location>

Thanks to you, Ermin Travisan for your help.

1

Ermin Trevisan

--Ermin Trevisan--
3548
| 6 3 7
Walchwil, Switzerland
--Ermin Trevisan--


Ermin Trevisan
On 11/9/16, 2:57 AM

1. Use the dbfilter parameter in the openerp-server.conf file. You have 2 options:

- %d: Odoo extracts the subdomain of a hostname except of "www". Examples: "www.subdomain.domain.tld" results in the database name "subdomain". "subdomain.domain.tld" results i the same database name "subdomain". "www.domain.tld" results in the database name "domain"!

- %h: Odoo takes the FQDN. Examples: "www.subdomain.domain.tld" results in the database name "www-subdomain-domain-tld". "subdomain.domain.tld" results in "subdomain-domain-tld" and so on.

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

2. In your Apache vhost definition proxy to the IP address and port of your Odoo server and forward the request headers:

You can either use the directive "ProxyReserveHost" or the options X-Forwarded-For (see http://stackoverflow.com/questions/6070335/retain-original-request-url-on-mod-proxy-redirect)  

If it is not possible to match database names from the host/domain name, you can use the module https://www.odoo.com/apps/modules/9.0/dbfilter_from_header/


I already know about the dbfilter, and all that works perfectly.

What I miss, is how to proxy from "bar.com/web" to "quz.mydomain.fr/web", so that "quz.mydomain.fr/web" gets in turn proxied to "mydomain.fr:8069/web" by the already in place configuration.

PY
on 11/9/16, 3:40 AM

What is the name of the database you want to connect to? Is it "bar" or "quz"? I'm not sure if it has to be that complicated. Anyway, with a proper rewrite you should be able to achieve your goal.

Ermin Trevisan
on 11/9/16, 4:12 AM

The database is "quz", and "bar.com" is the domain that should be visible.

PY
on 11/9/16, 4:25 AM

See my amended answer.

Ermin Trevisan
on 11/9/16, 5:29 AM

So, it isn't possible, on a single Odoo (8.0 by the way, forgot to mention) instance, to :

- proxy "foo.mydomain.fr", "xyz.mydomain.fr" to "mydomain.fr:8069" with respectively databses "foo" and "xyz" ;

- proxy "bar.com" to "mydomain.fr:8069" with database "quz" (can be anything, really) with or without the intermediate proxy "quz.mydomain.fr"

?

PY
on 11/9/16, 5:47 AM

The first one is for sure easily possible, because that's the common dbfilter use case. The second one might be possible with proper URL rewriting. But I do not understand why you don't want to name the database "bar" instead of "quz" in the first place.

Ermin Trevisan
on 11/9/16, 8:05 AM

It's just an example. In fact it is the same. But since the config file allow only one dbfilter, it doesn't really matter.

Or does it ? Can a dbfilter have an OR condition ? Like: ^%d$ | ^%h$

PY
on 11/9/16, 8:20 AM

No

Ermin Trevisan
on 11/9/16, 8:41 AM

The result of the dbfilter operation should match a single database which would not be the case in your example.

Ermin Trevisan
on 11/9/16, 8:44 AM

Thanks for your help. I'll try some rewrite rules and all that good stuff then.

PY
on 11/9/16, 8:48 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/8/16, 3:42 AM
Seen: 304 times
Last updated: 11/14/16, 3:56 AM