浏览 4.2k

按点赞数排序
按时间排序
当出现下面这行命令行输出时,Nginx相当于启动失败,新配置文件未生效:
root@nginx-deployment-6686f596f-xhjt8:/etc/nginx/conf.d# nginx -t
2020/09/17 06:00:56 [emerg] 115#115: host not found in upstream "nginx2-deployment" in /etc/nginx/conf.d/default.conf:2
nginx: [emerg] host not found in upstream "nginx2-deployment" in /etc/nginx/conf.d/default.conf:2
nginx: configuration file /etc/nginx/nginx.conf test failed如果新的配置文件生效,当Nginx连接nginx2-deployment时,在接收到RST报文、发生超时等,会重新选择到127.0.0.1:80这台server。
0
回答于2020-09-17 14:12
root@nginx-deployment-6686f596f-xhjt8:/etc/nginx/conf.d# nginx -t
2020/09/17 06:00:56 [emerg] 115#115: host not found in upstream "nginx2-deployment" in /etc/nginx/conf.d/default.conf:2
nginx: [emerg] host not found in upstream "nginx2-deployment" in /etc/nginx/conf.d/default.conf:2
nginx: configuration file /etc/nginx/nginx.conf test failed
root@nginx-deployment-6686f596f-xhjt8:/etc/nginx/conf.d# more default.conf
upstream test_upstream {
server nginx2-deployment;
server 127.0.0.1:80 backup;
}
server {
listen 80;
server_name nginx-test.ingageapp.com;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location /admin {
proxy_pass http://test_upstream;
}
@陶辉
0
回答于2020-09-17 14:02
可以将serviceB后加入backup选项,例如:
upstream test_default {
server serviceA;
server serviceB backup;
}
注意,不要使用hash类负载均衡算法,使用roundrobin、least conn等复制类扩展算法才有效。
另外,注意不要关闭next_upstream功能,而且http响应码、error、timeout已经配置到next_upstream中了。
0
回答于2020-09-17 13:55
你应该有一个默认的服务器来捕捉所有的,你可以返回404或更好地不响应(会节省一些带宽),通过返回444它是nginx特定的HTTP响应,只需关闭连接并返回任何内容
1、找不到,就会要求用户重新登陆,这由页面逻辑而定;
2、不同的上游服务都从同1个redis等中心化服务上存取session,就可以通用;
3、用http_cookie_变量取出cookie的值,再基于它进行哈希路由也是一个解决办法(Tengine上的session sticky是做这个的,但不支持开源Nginx;OpenResty上的upstream_list也有同样的效果,支持官方Nginx;其实官方Nginx的map模块也能实现同样的效果)
微信公众号
加入微信群