我已经成功地在几个容器化应用程序中使用了Traefik,并且我对使用LetsEncrypt的本机SSL支持感到满意(非常感谢Traefik团队)。然而,具体来说,要运行Odoo(开源ERP/CRM),我在后台和浏览器中通过javascript日志得到一个异常:Exception: bus.Bus unavailable
+调用栈在这里不重要。显然,这个异常的根本原因是Traefik没有代理到URL/longpolling
的请求,当odoo.conf文件中的参数workers > 1
时。
Odoo服务器公开两个不同的端口:
- 8069:对webapp的正常请求
- 7082:
/longpolling
下的聊天服务使用
我做了一个GitHub仓库,解释如何重现这个"bug";(我不知道这是一个错误,还是我不知道如何正确使用它)。
作为参考,我还添加了一个不使用SSL的nginx.conf
文件(只是为了简单起见)。
这是我用来运行Odoo + Traefik的docker-compose.yml
:
version: "2.3"
networks:
web:
external: true
services:
traefik:
image: "traefik:v2.4"
container_name: "traefik"
env_file: .env
environment:
- UID=2000
- GID=2000
ports:
- "80:80"
- "443:443"
command:
- --api.insecure=true
- --api.dashboard=true
- --api.debug=true
- --log=true
- --log.level=INFO
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --providers.file.filename=/dynamic.yml
- --providers.docker.network=web
- --entrypoints.http.address=:80
- --entrypoints.https.address=:443
- --certificatesresolvers.le.acme.httpchallenge=true
- --certificatesresolvers.le.acme.httpchallenge.entrypoint=http
- --certificatesresolvers.le.acme.email=${LETS_ENCRYPT_CONTACT_EMAIL}
- --certificatesresolvers.le.acme.storage=/letsencrypt/acme.json
networks:
- web
volumes:
- "${BASE_VOLUME_DIR}/traefik/conf/letsencrypt:/letsencrypt"
- "${BASE_VOLUME_DIR}/traefik/conf/dynamic.yml:/dynamic.yml"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
labels:
- traefik.enable=true
- traefik.http.routers.traefik-http.rule=Host(`${TRAEFIK_HOSTNAME}`)
- traefik.http.routers.traefik-http.entrypoints=http
- traefik.http.routers.traefik-http.service=traefik
- traefik.http.routers.traefik-http.middlewares=redirect@file
- traefik.http.routers.traefik-https.rule=Host(`${TRAEFIK_HOSTNAME}`)
- traefik.http.routers.traefik-https.entrypoints=https
- traefik.http.routers.traefik-https.tls=true
- traefik.http.routers.traefik-https.tls.options=default
- traefik.http.routers.traefik-https.service=traefik
- traefik.http.routers.traefik-https.tls.certresolver=le
- traefik.http.services.traefik.loadbalancer.server.port=8080
- traefik.http.routers.traefik-https.middlewares=gzip
- traefik.http.middlewares.gzip.compress=true
odoo:
image: registry.wisecoding.io/docker/odoo:11.0
container_name: odoo
networks:
- web
env_file: .env
ports:
- "8069:8069"
- "8072:8072"
volumes:
- "${BASE_VOLUME_DIR}/odoo/extra-addons:/opt/odoo/extra-addons"
- "${BASE_VOLUME_DIR}/odoo/data:/opt/odoo/data"
- "${BASE_VOLUME_DIR}/odoo/logs:/opt/odoo/logs"
- "${BASE_VOLUME_DIR}/odoo/conf:/opt/odoo/conf"
ulimits:
nofile:
soft: 65536
hard: 65536
labels:
- traefik.enable=true
- traefik.http.routers.odoo-http.rule=Host(`${ODOO_HOSTNAME}`)
- traefik.http.routers.odoo-http.entrypoints=http
- traefik.http.routers.odoo-http.service=odoo-http
- traefik.http.services.odoo-http.loadbalancer.server.port=8069
- traefik.http.routers.odoo-http.middlewares=redirect@file
- traefik.http.routers.odoo-https.rule=Host(`${ODOO_HOSTNAME}`)
- traefik.http.routers.odoo-https.entrypoints=https
- traefik.http.routers.odoo-https.service=odoo-https
- traefik.http.routers.odoo-https.tls.certresolver=le
- traefik.http.routers.odoo-https.middlewares=gzip
- traefik.http.services.odoo-https.loadbalancer.server.port=8069
#====> On the next line was my mistake. It was typo as pointed out by @Veikko
- traefik.http.routers.odoo-im-https.rule=Host(`${ODOO_HOSTNAME}`) && (PathPrefix(`/longpooling`))
- traefik.http.routers.odoo-im-https.entrypoints=https
- traefik.http.routers.odoo-im-https.service=odoo-im-https
- traefik.http.routers.odoo-im-https.tls.certresolver=le
- traefik.http.routers.odoo-im-https.middlewares=gzip,sslheader
- traefik.http.services.odoo-im-https.loadbalancer.server.port=8072
# middlewares
- traefik.http.middlewares.gzip.compress=true
- traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto=https
我找到的最接近的解决方案是在Traefik论坛上的这个问题,建议包括下面的行(我尝试过,但仍然不起作用):traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto = https
我可能错过了什么,但我想不出来。
想法吗?
正确的Odoo url路径为/longpolling
。检查你的Traefik和Odoo配置是否使用longpolling
,而不是longpooling
,例如,Traefik的Odoo容器标签…PathPrefix('/longpooling')"
→…PathPrefix('/longpolling')"
.