我的日志中不断出现此问题。我看到了一些关于可能是什么问题以及如何解决它的参考资料,但没有运气解决它。
日志:
2023-05-08 15:41:42,422 1130561 INFO 实时长轮询:127.0.0.1 - - [2023-05-08 15:41:42]“GET /websocket HTTP/1.0”400 281 0.003553
odoo.conf:
[options]
db_user = odoo16
dbfilter = live
list_db = False
proxy_mode = True
xmlrpc_port = 8069
gevent_port = 8072
longpolling_port = False
limit_memory_hard = 741667999
limit_memory_soft = 593334399
limit_request = 8192
limit_time_cpu = 120000
limit_time_real = 180000
max_cron_threads = 2
workers = 9
logfile = /var/log/odoo16/odoo-server.log
nginx.conf:
upstream live {
server localhost:8069 weight=1 fail_timeout=3000s;
}
upstream livechat {
server localhost:8072 weight=1 fail_timeout=3000s;
}
# WWW -> NON WWW
server {
listen 443 ssl http2;
server_name www.live.com;
ssl_certificate /etc/letsencrypt/live/live.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/live.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/live.com/chain.pem;
include snippets/ssl.conf;
include snippets/letsencrypt.conf;
return 301 https://live.com$request_uri;
}
server {
listen 443 ssl http2;
server_name live.com;
# Specifies the maximum accepted body size of a client request,
# as indicated by the request header Content-Length.
client_max_body_size 100M;
# add ssl specific settings
keepalive_timeout 60;
# increase proxy buffer to handle some OpenERP web requests
proxy_buffers 16 64k;
proxy_buffer_size 128k;
location / {
proxy_pass http://live;
# Force timeouts if the backend dies
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
add_header X-Frame-Options "SAMEORIGIN";
# Set headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $remote_addr;
proxy_http_version 1.1;
# Set timeouts
proxy_connect_timeout 3600;
proxy_send_timeout 3600;
proxy_read_timeout 3600;
send_timeout 3600;
# By default, do not forward anything
proxy_redirect off;
}
location /longpolling/ {
proxy_pass http://livechat;
# Force timeouts if the backend dies
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
# Set headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
# Set timeouts
proxy_connect_timeout 3600;
proxy_send_timeout 3600;
proxy_read_timeout 3600;
send_timeout 3600;
# By default, do not forward anything
proxy_redirect off;
}
# Cache some static data in memory for 60mins.
# under heavy load this should relieve stress on the Odoo web interface a bit.
location ~* /[0-9a-zA-Z_]*/static/ {
proxy_cache_valid 200 60m;
proxy_buffering on;
expires 864000;
proxy_pass http://live;
}
location /websocket {
proxy_redirect off;
proxy_pass http://livechat;
}
access_log /var/log/nginx/odoo-ssl.access.log;
error_log /var/log/nginx/odoo-ssl.error.log;
# SSL parameters
ssl_certificate /etc/letsencrypt/live/live.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/live.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/live.com/chain.pem;
include snippets/ssl.conf;
include snippets/letsencrypt.conf;
}
server {
listen 80;
server_name www.live.com live.com;
include snippets/letsencrypt.conf;
return 301 https://live.com$request_uri;
}
我不确定是否相关,但我在 VPS 上托管了 Odoo,也许某些端口未打开。
此外,我也有此日志,它们可能与该问题有关。
2023-05-08 16:48:36,679 1131879 INFO ? odoo.sql_db: ConnectionPool(used=1/count=1/max=64): Closed 1 connections to 'application_name=odoo-1131879 user=odoo16 sslmode=prefer dbname=staging'
2023-05-08 16:49:23,013 1131878 INFO ? odoo.sql_db: ConnectionPool(used=1/count=1/max=64): Closed 1 connections to 'application_name=odoo-1131878 user=odoo16 sslmode=prefer dbname=live_live'
2023-05-08 16:49:23,028 1131878 INFO ? odoo.sql_db: ConnectionPool(used=1/count=1/max=64): Closed 1 connections to 'application_name=odoo-1131878 user=odoo16 sslmode=prefer dbname=staging'
在我的例子中,400 HTTP 代码是由于缺少标头设置引起的。
注意:这些标头存在于 OP 的配置中,只是不在正确的范围内。
proxy_http_version 1.1;
proxy_set_header Host $host;
location /websocket {
proxy_pass http://livechat;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
如果您处于调试模式,如果 Websocket 连接成功(至少在 odoo16 中),您应该会在浏览器控制台中看到这些行。
8/26/2023, 4:16:28 PM - [onOpen] websocket_worker_bundle:74:45
8/26/2023, 4:16:28 PM - [onMessage] websocket_worker_bundle:72:10