1、开发的数据库分片管理平台使用nginx代理报错
页面访问执行没有报错,chrome按F12有如下报错
WebSocket connection to 'ws://mdb.xxx.cn/app/shard_createtable/' failed:
(匿名) @ shard_createtable.js:140
2、nginx配置如下参数并重启后再次访问正常
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
3、nginx详细配置
nginx.conf主配置:
user www;
worker_processes 16;
error_log /data/applogs/nginxlogs/error.log;
pid /data/applogs/nginxlogs/nginx.pid;
events {
use epoll;
worker_connections 65530;
}
http {
limit_conn_zone $http_x_forwarded_for zone=conn:10m;
#limit_conn_zone $binary_remote_addr zone=conn:10m;
limit_conn_log_level info;
limit_req_zone $http_x_forwarded_for zone=req:10m rate=20r/s;
#limit_req_zone $binary_remote_addr zone=req:10m rate=12r/s;
limit_req_log_level info;
limit_conn conn 15;
limit_req zone=req burst=20;
charset utf-8;
include mime.types;
default_type application/octet-stream;
log_format main '$http_x_forwarded_for - $remote_user [$time_local] '
'"$request_method $scheme://$http_host$request_uri $server_protocol" '
'$status $body_bytes_sent "$http_referer" '
'"$cookie___utma" '
'"$cookie___utmv" '
'[$upstream_addr $upstream_status $upstream_response_time] '
'[$http_accept] '
'"$http_user_agent" ';
access_log /data/applogs/nginxlogs/access.log main;
server_tokens off;
sendfile on;
keepalive_timeout 65;
server_names_hash_bucket_size 128;
client_header_buffer_size 512k;
large_client_header_buffers 4 128k;
client_max_body_size 3m;
#add for compress
gzip_static on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
#gzip_http_version 1.1;
gzip_http_version 1.0;
gzip_comp_level 6;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
postpone_output 1460;
gzip_proxied any;
gzip_disable "MSIE [1-6]\.";
tcp_nodelay on;
client_body_buffer_size 512k;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_buffer_size 8k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_temp_path /tmp/proxy_temp_dir;
proxy_cache_path /tmp/proxy_cache_dir levels=1:2 keys_zone=cache_one:9192m inactive=1d max_size=30g;
proxy_set_header Host $host;
proxy_set_header Proxy-Client-IP $remote_addr;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
upstream mysqlslow_server {
server 127.0.0.1:8080;
}
upstream dbplatform_server {
server 127.0.0.1:8000;
}
upstream dbbackup_server {
server 127.0.0.1:8001;
}
server {
listen 80;
autoindex off;
server_name localhost;
root /data/soft;
location / {
index index.html index.shtml;
allow 10.0.0.0/8;
deny all;
}
}
include vhosts/*.conf;
}
子配置vhosts/dbplatform.conf
server {
listen 80;
server_name mdb.xxxx.cn;
root /tmp;
access_log /data/applogs/nginxlogs/mdb.ds.gome.com.cn_access.log main;
error_log /data/applogs/nginxlogs/mdb.ds.gome.com.cn_error.log;
location / {
index index.html index.shtml;
allow 10.0.0.0/8;
deny all;
proxy_pass http://dbplatform_server;
}
}
4、nginx配置重新生效命令
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
/usr/local/nginx/sbin/nginx -s reload