关于nginx反向代{过}{滤}理的问题求助
我用dockers新建了两个一样的实例,想用nginx来做反向代{过}{滤}理,但是开启nginx就一直报302的错误,前端发过来的请求,nginx给每个实例都分发了,导致实例之间相互相应造成重定向。这个问题困扰我很久了,希望有大佬指点一下。万分感谢。nginx配置如下pstream odoo {
# server 10.13.166.108:8069;
server127.0.0.1:8889 weight=100 max_fails=2 fail_timeout=15;
server127.0.0.1:8888 weight=100 max_fails=2 fail_timeout=15;
}
#upstream odoochat {
# server 10.13.166.108:8072;
# server127.0.0.1:8888;
# server127.0.0.1:8889;
# server127.0.0.1:8888;
#}
server {
listen 8081;
# web/login;
# server_name 10.13.166.108;
# Add Headers for odoo proxy mode
# proxy_set_header X-Forwarded-Host $host:8081;
# 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;
# Add Headers for odoo proxy mode
proxy_set_header X-Forwarded-Host $host:8081;
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;
# log
access_log /var/log/nginx/odoo.access.log;
error_log /var/log/nginx/odoo.error.log;
# cache static data
location ~* /web/static/ {
proxy_cache_valid 200 60m;
proxy_buffering on;
expires 864000;
proxy_pass http://odoo;
}
# Redirect longpoll requests to odoo longpolling port
# location /longpolling {
# proxy_pass http://odoochat;
# proxy_set_header Host $host:8081;
# proxy_redirect off;
# proxy_set_headerX-Real-IP $remote_addr;
# proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
# }
# Redirect requests to odoo backend server
location / {
proxy_redirect off;
proxy_pass http://odoo;
# proxy_set_header Host $host:8081;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# common gzip
gzip_types text/css text/scss text/plain text/xml application/xml application/json application/javascript;
gzip on;
}
报错如下:
你这是架设手游用反向代{过}{滤}理? joexv 发表于 2020-12-8 14:07
你这是架设手游用反向代{过}{滤}理?
不是,是个网站 你先描述清楚你要转发哪些请求 proxy_set_header X-Forwarded-Host $host:8081;
改成:
proxy_set_header X-Forwarded-Host $host;
我写博客是前后端分离,也是nginx反向代{过}{滤}理 后端实例单个,或ip_hash方式可以访问吗? 本帖最后由 LIN168168 于 2020-12-8 16:02 编辑
给你个参考
# 根据项目名区分代{过}{滤}理的地址与端口
location /test {
proxy_pass http://127.0.0.1:39002;
}
location /test -admin {
proxy_pass http://127.0.0.1:39003;
} 代{过}{滤}理 两个字竟然会自动加字 第一次知道 $host:8081; 就不对,你8081代{过}{滤}理到其他端口 你还8081啊
页:
[1]
2