首页 > 解决方案 > Odoo &NGINX:轮询进程无法通过 NGINX 反向代理连接到数据库

问题描述

我正在努力解决轮询进程(用于 IM 消息)引发的 500 HTTP 错误 - 据我所知,因为轮询进程无法连接到 PostgreSQL(但 Odoo 主进程可以)

症状

Odoo 中的一切工作都很好,除了 IM:messagges 不会自动刷新,Odoo 指责失去连接并自动恢复(有时会话甚至过期)。

没有 IM 消息丢失:刷新网页会显示最新的 IM 消息。

环境

配置文件

Odoo.conf

[options]
addons_path = ...
admin_passwd = ...
csv_internal_sep = ,
data_dir = /var/lib/odoo/.local/share/Odoo
db_host = localhost
db_maxconn = 64
db_name = False
db_password = ...
db_port = 5432
db_sslmode = prefer
db_template = template0
db_user = odoo
dbfilter = odoo
list_db = False
demo = {}
email_from = False
geoip_database = /usr/share/GeoIP/GeoLite2-City.mmdb
http_enable = True
http_interface =
http_port = 8069
import_partial =
limit_memory_hard = 2684354560
limit_memory_soft = 2147483648
limit_request = 8192
limit_time_cpu = 120
limit_time_real = 240
limit_time_real_cron = -1
; xmlrpc = True ; Already tried uncommenting this
; xmlrpcs = False ; Already tried uncommenting this
; xmlrpc_port = 8069 ; Already tried uncommenting this
log_db = False
log_db_level = warning
log_handler = :INFO
log_level = info
logrotate = True
logfile = /var/log/odoo/odoo-server.log
longpolling_port = 8072
max_cron_threads = 4
osv_memory_age_limit = False
osv_memory_count_limit = False
pg_path =
pidfile =
proxy_mode = True
reportgz = False
screencasts =
screenshots = /tmp/odoo_tests
server_wide_modules = base,web
smtp_password = False
smtp_port = 25
smtp_server = localhost
smtp_ssl = False
smtp_user = False
syslog = False
test_enable = False
test_file =
test_tags = None
transient_age_limit = 1.0
translate_modules = ['all']
unaccent = False
upgrade_path =
without_demo = False
workers = 9 ; Already tried with 2. As there are 4 virtual CPUs: 9 = 4*2 + 1

NIGINX

# Odoo Upstreams
upstream intranet.com {
    server 127.0.0.1:8069;
}

upstream intranet-chat.com {
    server 127.0.0.1:8072;
}

# http to https redirection
server {
    listen 80;
    server_name intranet.com;
    server_name www.intranet.com;
    return 301 https://intranet.com$request_uri;
}

server {
    listen 443 ssl;
    server_name intranet.com;
    access_log /var/log/nginx/odoo_access.log;
    error_log /var/log/nginx/odoo_error.log;
   
    # SSL
    ssl_certificate /etc/nginx/certificates/intranet.crt;
    ssl_certificate_key /etc/nginx/certificates/intranet.rsa;

    # Proxy settings
    proxy_read_timeout 720s;
    proxy_connect_timeout 720s;
    proxy_send_timeout 720s;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;

    # Request for root domain
    location / {
       proxy_redirect off;
       proxy_pass http://intranet.com;
    }

    # Chat
    location /longpolling { # Commenting this block causes the 500 HTTP error not reporting but the issue persists (IM messages doesn't show automatically)
         proxy_pass http://intranet-chat.com;
    }

    # Cache static files
    location ~* /web/static/ {
        proxy_cache_valid 200 90m;
        proxy_buffering on;
        expires 864000;
        proxy_pass http://intranet.com;
    }

    # Gzip compression
    gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript;
    gzip on;

}

PostgreSQL

# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             all                                     peer
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

日志

Chrome 控制台(重复显示此消息)

web.assets_common.js:formatted:15849 POST https://intranet.com/longpolling/poll 500 (Internal Server Error)

odoo.log(重复显示此消息)

2021-06-24 22:33:33,958 269061 INFO ? longpolling: 192.168.40.36 - - [2021-06-24 22:33:33] "POST /longpolling/poll HTTP/1.0" 500 140 0.001650
2021-06-24 22:33:33,967 269061 INFO ? odoo.sql_db: Connection to the database failed

NGINX odoo_error.log(重复显示此消息)

2021/06/24 16:52:08 [error] 302077#302077: *56538 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.40.36, server: intranet.com, request: "POST /longpolling/poll HTTP/1.1", upstream: "http://127.0.0.1:8072/longpolling/poll", host: "intranet.com", referrer: "https://intranet.com/web"

故障排除

root@SRVODOO:/etc/odoo# netstat -ntlp | grep LISTEN
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      804/nginx: master p
tcp        0      0 0.0.0.0:8069            0.0.0.0:*               LISTEN      713/python3
tcp      221      0 0.0.0.0:8072            0.0.0.0:*               LISTEN      967/python3
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      804/nginx: master p
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      687/systemd-resolve
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      758/sshd: /usr/sbin
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      821/postgres
tcp6       0      0 :::22                   :::*                    LISTEN      758/sshd: /usr/sbin
tcp6       0      0 :::5432                 :::*                    LISTEN      821/postgres

root@SRVODOO:/etc/odoo# telnet 127.0.0.1 8072
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.


root@SRVODOO:/etc/odoo# ufw status
Status: active

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
8069                       ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
25/tcp                     ALLOW       Anywhere
389                        ALLOW       Anywhere
5432                       ALLOW       Anywhere
8072                       ALLOW       Anywhere
22/tcp (v6)                ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
8069 (v6)                  ALLOW       Anywhere (v6)
443/tcp (v6)               ALLOW       Anywhere (v6)
25/tcp (v6)                ALLOW       Anywhere (v6)
389 (v6)                   ALLOW       Anywhere (v6)
5432 (v6)                  ALLOW       Anywhere (v6)
8072 (v6)                  ALLOW       Anywhere (v6)

笔记

标签: postgresqlnginxodoolong-pollingodoo-14

解决方案


解决了!问题是我在 nginx.conf 中评论了这一行:

multi_accept on;

所以,取消注释一切都很好!


推荐阅读