概述
**
错误配置
**
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on; keepalive_timeout 65;
types_hash_max_size 2048;
proxy_buffers 240 4k;
include mime.types;
default_type application/octet-stream;
upstream durl{
server 192.167.120.17:8080;
server 192.167.120.18:8080;
server 192.167.120.19:8080;
server 192.167.120.20:8080;
server 192.167.120.21:8080;
#若本机IP可用localhost,有时127.0.0.1无效
ip_hash;
}
server {
listen 0.0.0.0:80;
client_max_body_size 20M;
location / {
root html;
index index.html index.htm;
}
location /api{
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 修改为后端程序的IP和端口号
proxy_pass http://durl;
proxy_read_timeout 1800;
}
}
}
stream {
upstream backend {
hash $remote_addr consistent;
server 127.1.0.1:12346;
server 127.2.0.1:12347;
server 127.4.0.1:12348;
}
server {
listen 12345;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass http://backend;
}
}
**
正确配置
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on; keepalive_timeout 65;
types_hash_max_size 2048;
proxy_buffers 240 4k;
include mime.types;
default_type application/octet-stream;
upstream durl{
server 192.167.120.17:8080;
server 192.167.120.18:8080;
server 192.167.120.19:8080;
server 192.167.120.20:8080;
server 192.167.120.21:8080;
#若本机IP可用localhost,有时127.0.0.1无效
ip_hash;
}
server {
listen 0.0.0.0:80;
client_max_body_size 20M;
location / {
root html;
index index.html index.htm;
}
location /api{
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 修改为后端程序的IP和端口号
proxy_pass http://durl;
proxy_read_timeout 1800;
}
}
}
stream {
upstream backend {
hash $remote_addr consistent;
server 127.1.0.1:12346;
server 127.2.0.1:12347;
server 127.4.0.1:12348;
}
server {
listen 12345;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass backend;
}
}
错误原因:在stream中配置proxy_pass的时候加了http:.//
最后
以上就是欢喜蜜蜂为你收集整理的nginx负载均衡配置错误记录的全部内容,希望文章能够帮你解决nginx负载均衡配置错误记录所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复