当前位置:首页 > ODOO > 正文内容

odoo里如何使用db-filter绑定域名到对应数据库

oozj1年前 (2023-04-13)ODOO1890

在Odoo中,可以通过 db-filter 参数来将不同的域名绑定到不同的数据库。以下是一些基本的步骤:

在服务器上创建多个Odoo数据库,每个数据库对应一个不同的域名。

在启动Odoo时,使用 --db-filter 参数来指定要使用的数据库。例如:

./odoo-bin --db-filter=mydomain.com,mydatabase --addons-path=addons 
这将使Odoo仅使用名为 mydatabase 的数据库来处理来自 mydomain.com 域名的请求。如果有多个域名,则可以使用逗号分隔它们,并在后面加上相应的数据库名称。

配置Web服务器以将请求转发到正确的Odoo实例。例如,可以使用NGINX配置文件中的以下指令:

location / {
    proxy_pass http://127.0.0.1:8069;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # Add the following line to include the domain name in the request URL
    proxy_set_header X-Odoo-dbfilter "%{HTTP_HOST}";
    # Add the following line to include the HTTP scheme in the request URL
    proxy_set_header X-Forwarded-Proto $scheme;
}
 

这会将请求转发到本地端口 8069,并在HTTP请求头中添加 X-Odoo-dbfilter 标头,该标头将设置为请求的域名。

在Odoo中配置具有正确数据库名称的数据库管理员帐户,以确保Odoo可以正确访问所需的数据库。

在配置文件里指定:

在Odoo的配置文件中指定 db-filter 参数,而无需在命令行中指定。以下是一个示例配置文件:

[options]
; Set the location of the Odoo addons directory
addons_path = /opt/odoo/addons,/opt/odoo/custom_addons
; Set the database name prefix for this Odoo instance
db_name = myprefix_
; Set the database filter to bind domains to different databases
dbfilter = %d
; Set the superuser password for the Odoo instance
admin_passwd = mysecretpassword
; Set the listening port for the Odoo instance
http_port = 8069
; Set the log file location and level
logfile = /var/log/odoo/odoo.log
log_level = info
 

示例中,dbfilter = %d 将启用数据库过滤器,并将 %d 替换为请求的域名。例如,如果请求的域名为 mydomain.com,则Odoo将自动连接到名为 myprefix_mydomain_com 的数据库。

请注意,如果您使用了 db-filter 参数,则必须将请求路由到正确的Odoo实例,以便Odoo可以正确识别要使用的数据库。如果您正在使用反向代理服务器(如NGINX),则可以在代理服务器上设置相应的标头以指定数据库名称。

如何根据二级域名匹配

要根据二级域名匹配Odoo数据库,请使用以下步骤:

在服务器上创建多个Odoo数据库,每个数据库对应一个不同的二级域名。

在启动Odoo时,使用 --db-filter 参数来指定要使用的数据库。例如:

./odoo-bin --db-filter="^%h$" --addons-path=addons 

这将使Odoo仅使用与请求的二级域名匹配的数据库来处理请求。 %h 通配符将被替换为请求的二级域名。正则表达式 ^%h$ 将匹配完全与请求的二级域名相同的数据库名称。

配置Web服务器以将请求转发到正确的Odoo实例,并将请求的二级域名传递给Odoo。例如,可以使用NGINX配置文件中的以下指令:

location / {
    proxy_pass http://127.0.0.1:8069;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # Add the following line to include the domain name in the request URL
    proxy_set_header X-Odoo-dbfilter "%{HTTP_HOST}";
    # Add the following line to include the HTTP scheme in the request URL
    proxy_set_header X-Forwarded-Proto $scheme;
    # Add the following line to pass the second-level domain to Odoo
    proxy_set_header X-Second-Level-Domain $http_host;
}
 

在此示例中,X-Second-Level-Domain 标头将请求的二级域名传递给Odoo。该标头可以在Odoo中使用,以便根据请求的二级域名选择正确的数据库。

在Odoo中配置具有正确数据库名称的数据库管理员帐户,以确保Odoo可以正确访问所需的数据库。

扫描二维码推送至手机访问。

版权声明:本文由千城笔记发布,如需转载请注明出处。

本文链接:https://oozj.org/39.html

分享给朋友:

相关文章

odoo的哪些版本的哪些开发方式不再通用

odoo的哪些版本的哪些开发方式不再通用

Odoo是一个持续更新和发展的开源ERP软件平台,它的新版本会引入新的特性、技术和编程方式,同时也可能废弃或不再支持一些旧的特性、技术和编程方式。以下是一些Odoo版本和开发方式的变化,这些方式在新版...

odoo16怎样在群晖docker里运行模块脚手架

odoo16怎样在群晖docker里运行模块脚手架

/usr/bin/odoo scaffold my /mnt/extra-addons...

odoo16 销售员只可以看到自己建立的联系人(客户)

odoo16 销售员只可以看到自己建立的联系人(客户)

当使用这个规则作为Odoo数据库的访问限制条件时,只有与当前用户相关的记录才能被访问。这个规则涉及的条件是:'create_uid' 等于当前用户的 ID'user_id' 等于当前用户的 ID'us...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。