如何更改 odoo 的 nginx 配置上下文 URI
我的 odoo15 对于这个 URL 工作得很好 -> https://vidatest.xyz 下面是 odoo 文档建议的 nginx 配置。
#odoo server
upstream odoo {
server 127.0.0.1:8069;
}
upstream odoochat {
server 127.0.0.1:8072;
}
# http -> https
server {
listen 80;
server_name vidatest.xyz;
rewrite ^(.*) https://$host$1 permanent;
}
server {
listen 443 ssl;
server_name vidatest.xyz;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
# Add Headers for odoo proxy mode
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;
# SSL parameters
ssl_certificate /etc/certs/certs_14March2022/98fa7f5df02b430e.crt;
ssl_certificate_key /etc/certs/generated-private-key.key;
ssl_session_timeout 30m;
ssl_protocols TLSv1.2;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
# log
access_log /var/log/nginx/odoo.access.log;
error_log /var/log/nginx/odoo.error.log;
# Redirect longpoll requests to odoo longpolling port
location /longpolling {
proxy_pass http://odoochat;
}
# Redirect requests to odoo backend server
location / {
proxy_redirect off;
proxy_pass http://odoo;
}
# common gzip
gzip_types text/css text/scss text/plain text/xml application/xml application/json application/javascript;
gzip on;
}
但是,我的要求是使用 https://vidatest.xyz
不是用于 odoo,而是用于我的应用程序。
odoo 应该可以在这个 URL 上运行 -> https://vidatest.xyz/web
因此,我更新了 &在 nginx 配置中添加了以下更改
# Redirect requests to odoo backend server
location /web {
proxy_redirect off;
proxy_pass http://odoo;
}
# Redirect requests to odoo backend server
location / {
proxy_redirect off;
proxy_pass http://mybank.com;
}
现在,odoo 正在加载此 URL -> https://vidatest.xyz/web
但成功登录后抛出以下错误
错误堆栈:
POST https://vidatest.xyz/mail/init_messaging 405 (Not Allowed)
POST https://vidatest.xyz/longpolling/poll 405 (Not Allowed)
Uncaught SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at XMLHttpRequest.<anonymous> (web.assets_backend.min.js:585:55)
(anonymous) @ web.assets_backend.min.js:585
load (async)
(anonymous) @ web.assets_backend.min.js:583
jsonrpc @ web.assets_backend.min.js:582
rpc @ web.assets_backend.min.js:590
(anonymous) @ web.assets_backend.min.js:3324
legacyEnv.session.rpc @ web.assets_backend.min.js:3323
(anonymous) @ web.assets_common.min.js:5057
rpc @ web.assets_common.min.js:5057
_trigger_up @ web.assets_backend.min.js:5924
trigger_up @ web.assets_common.min.js:4855
call @ web.assets_common.min.js:4908
_rpc @ web.assets_common.min.js:4908
_makePoll @ web.assets_backend.min.js:5914
_poll @ web.assets_backend.min.js:5914
startPolling @ web.assets_backend.min.js:5913
startPolling @ web.assets_backend.min.js:5893
prototype.<computed> @ web.assets_common.min.js:4716
_startElection @ web.assets_backend.min.js:5900
startPolling @ web.assets_backend.min.js:5890
Odoo &蟒蛇版本:
root@ip-172-31-42-237:/var/log# systemctl status odoo
● odoo.service - Odoo15
Loaded: loaded (/etc/systemd/system/odoo.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-04-06 10:26:20 UTC; 6min ago
Main PID: 420828 (python3)
Tasks: 4 (limit: 4623)
Memory: 138.1M
CGroup: /system.slice/odoo.service
└─420828 /opt/odoo/odoo-venv/bin/python3 /opt/odoo/odoo/odoo-bin -c /etc/odoo.conf -u vida_product
python3 --version
Python 3.8.10
/usr/bin/pip --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
My odoo15 works fine for this URL -> https://vidatest.xyz and below is the nginx configuration as suggested by odoo documentation.
#odoo server
upstream odoo {
server 127.0.0.1:8069;
}
upstream odoochat {
server 127.0.0.1:8072;
}
# http -> https
server {
listen 80;
server_name vidatest.xyz;
rewrite ^(.*) https://$host$1 permanent;
}
server {
listen 443 ssl;
server_name vidatest.xyz;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
# Add Headers for odoo proxy mode
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;
# SSL parameters
ssl_certificate /etc/certs/certs_14March2022/98fa7f5df02b430e.crt;
ssl_certificate_key /etc/certs/generated-private-key.key;
ssl_session_timeout 30m;
ssl_protocols TLSv1.2;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
# log
access_log /var/log/nginx/odoo.access.log;
error_log /var/log/nginx/odoo.error.log;
# Redirect longpoll requests to odoo longpolling port
location /longpolling {
proxy_pass http://odoochat;
}
# Redirect requests to odoo backend server
location / {
proxy_redirect off;
proxy_pass http://odoo;
}
# common gzip
gzip_types text/css text/scss text/plain text/xml application/xml application/json application/javascript;
gzip on;
}
However, my requirement is to use https://vidatest.xyz
not for odoo but for my application.
odoo should work on this URL -> https://vidatest.xyz/web
Thus, I updated & added the below changes to the nginx configuration
# Redirect requests to odoo backend server
location /web {
proxy_redirect off;
proxy_pass http://odoo;
}
# Redirect requests to odoo backend server
location / {
proxy_redirect off;
proxy_pass http://mybank.com;
}
Now, odoo is loading for this URL -> https://vidatest.xyz/web
but throws the below error after successful login
Error stack:
POST https://vidatest.xyz/mail/init_messaging 405 (Not Allowed)
POST https://vidatest.xyz/longpolling/poll 405 (Not Allowed)
Uncaught SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at XMLHttpRequest.<anonymous> (web.assets_backend.min.js:585:55)
(anonymous) @ web.assets_backend.min.js:585
load (async)
(anonymous) @ web.assets_backend.min.js:583
jsonrpc @ web.assets_backend.min.js:582
rpc @ web.assets_backend.min.js:590
(anonymous) @ web.assets_backend.min.js:3324
legacyEnv.session.rpc @ web.assets_backend.min.js:3323
(anonymous) @ web.assets_common.min.js:5057
rpc @ web.assets_common.min.js:5057
_trigger_up @ web.assets_backend.min.js:5924
trigger_up @ web.assets_common.min.js:4855
call @ web.assets_common.min.js:4908
_rpc @ web.assets_common.min.js:4908
_makePoll @ web.assets_backend.min.js:5914
_poll @ web.assets_backend.min.js:5914
startPolling @ web.assets_backend.min.js:5913
startPolling @ web.assets_backend.min.js:5893
prototype.<computed> @ web.assets_common.min.js:4716
_startElection @ web.assets_backend.min.js:5900
startPolling @ web.assets_backend.min.js:5890
Odoo & python versions:
root@ip-172-31-42-237:/var/log# systemctl status odoo
● odoo.service - Odoo15
Loaded: loaded (/etc/systemd/system/odoo.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-04-06 10:26:20 UTC; 6min ago
Main PID: 420828 (python3)
Tasks: 4 (limit: 4623)
Memory: 138.1M
CGroup: /system.slice/odoo.service
└─420828 /opt/odoo/odoo-venv/bin/python3 /opt/odoo/odoo/odoo-bin -c /etc/odoo.conf -u vida_product
python3 --version
Python 3.8.10
/usr/bin/pip --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你想做的事情有点棘手。您可能无法实现它,因为 Odoo 使用 /web 作为转发到后端的主要分母。您正在尝试提供:
https://vidatest.xyz
- 另一个网站https://vidatest.xyz/web
- odoo但 Odoo 使用完整域或子域作为自己的资产并对其进行管理。这就是为什么你会遇到以下错误。
你的问题更多的是 Nginx 问题而不是 Odoo 问题。最简单的解决方案是将 Odoo 放在子域中,并从主域提供您想要的任何内容。例如:
https://odoo.vidatest.xyz
Odoo 进行的每次调用都会针对该子域。如果您坚持要部署的方式,请检查
Settings > 中的
。将值设置为您要使用的完整域,如果不存在,请创建它。还添加另一个带有键web.base.url
关键参数。技术>启用开发者模式后的系统参数web.base.url.freeze
和值True
的参数。看看这是否适合你。如果没有,您可能需要将引用的调用从 Nginx 重定向到您正在使用的完整路径。此外,您可能还需要设置长轮询端口的路径才能与/web/longpolling
一起使用。我不确定,但最终工作版本可能是https://vidatest.xyz/web/web
所以它应该很棘手。What you are trying to do is a bit tricky. You may not be able to achieve it because Odoo uses /web as the main denominator to forward to backend. You are trying to serve:
https://vidatest.xyz
- another websitehttps://vidatest.xyz/web
- odooBut Odoo uses the full domain or the subdomain as its own and manages it as such. That is why you are getting below error.
Your problem is more of a Nginx problem rather than an Odoo problem. The easiest solution is to put Odoo in a subdomain and serve whatever you want from the main domain. For example:
https://odoo.vidatest.xyz
Than each call Odoo makes would be to that subdomain.If you insist the way you want to deploy, check
web.base.url
key parameter inSettings > Technical > System Parameters
after enabling developer mode. Set the value to the full domain you want to use, if it doesn't exists create it. And also add another parameter with keyweb.base.url.freeze
and valueTrue
. See if that works for you. If it doesn't you may need to redirect the referred calls from Nginx to the full path you are using. Also, you may need to set the path of the longpolling port to work with/web/longpolling
as well. I am not sure but final working version might behttps://vidatest.xyz/web/web
so it should be tricky.