1

The first two vhosts works as expected. The second one proxy a Odoo server. I would like to make another proxy from my secondary domain to my Odoo server. However, Odoo must receive the subdomain matching the database, else it won't serve it.

Here's my code for now:

# static homepage

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


# 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>


# a secondary domain
# should point to a specific database

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

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

    ProxyVia On
</VirtualHost>


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

<Location /web/database>
    Order deny,allow
    Deny from all
    Allow from x.x.x.x
</Location>

I'm not really into server management, so I don't know much (even after reading the docs).


Forgot to mention what I get in response:

  • secondary-domain.com gives me a 502 Proxy Error
  • some_database.mydomain.fr works as expected

If I put the third <VirtualHost/> bloc in second position, the whole site mydomain.fr lags and that does not solve the 502 Proxy Error for my secondary domain.

If I quote the ProxyPreserveHost directive, going to secondary-domain.com leads to secondary-domain.com, some_database.mydomain.fr... What is happening here ?


I need confirmation that this can be done and that my setup is doing that:

  1. User asks for secondary-domain.com
  2. Third vhost entry proxies the request to some_database.mydomain.fr
  3. Second vhost entry proxies the request to mydomain.fr:8069
1

The first two vhosts works as expected.

Kind of. They share the same ServerName which does not make sense since what's unique about a vhost is the port+servername combination.

Apache here is actually silently using the first vhost definition when it receives a http://mydomain.fr or http://www.mydomain.fr/. For all other *.mydomain.fr it will use the second vhost. Which is what you want I guess, but it's akwardly writtent and prone to diagnostic bugs.

However, Odoo must receive the subdomain matching the database, else it won't serve it.

That's the purpose of "ProxyPreserveHost On", it pass alongs the name used by the HTTP client down to the app behind the reverse proxy. Use it in your second vhost.

Your third vhost seems just fine (it does have the "ProxyPreserveHost On").

  • Thanks for responding. So, my virtualhost setup is correct ? Something must be off, since I get this 502 proxy error. Can you confirm what I think my setup is doing: 1. User asks for secondary-domain.com 2. Third vhost entry proxies the request to some_database.mydomain.fr 3. Second vhost entry proxies the request to mydomain.fr:8069 – Yann May 10 '16 at 12:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.