首页 > 系统相关 >nginx配置增加代替头部proxy_set_header信息upgrade支持WebSocket--笔记

nginx配置增加代替头部proxy_set_header信息upgrade支持WebSocket--笔记

时间:2022-10-26 11:33:26浏览次数:50  
标签:set http log nginx server header proxy WebSocket

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

标签:set,http,log,nginx,server,header,proxy,WebSocket
From: https://www.cnblogs.com/hsjz-xinyuan/p/16827660.html

相关文章

  • Java知识33 集合框架 List接口 Map 和set【多测师】
    一、Java集合框架1.Java提供的特设类如:DictionaryVectorStack和Properties这些类来储存和操作对象组2.通过这些接口实现集合如:LinkedListHashSet和TreeSet,集合框架是......
  • As the default settings are now deprecated, you should set the endpoint inste
    k8s安装containerd后,使用crictl出现报错   解决方法:[root@k8s-master~]#cat/etc/crictl.yamlruntime-endpoint:unix:///run/containerd/containerd.sockim......
  • JAVA---Set集合底层源码分析
    1.Set集合介绍      常用方法,添加,删除和遍历 Set接口对象不能使用索引获取,他是无序的,没有索引。set集合无序,所以没有修改和查看某个元素,因为某个位置上是......
  • 京东云开发者| Redis数据结构(二)-List、Hash、Set及Sorted Set的结构实现
    1引言之前介绍了Redis的数据存储及String类型的实现,接下来再来看下List、Hash、Set及SortedSet的数据结构的实现。2ListList类型通常被用作异步消息队列、文章列表查......
  • Set
    一般,我们对于集合,要立即想到的三种遍历方式是: 迭代器。普通for循环增强for循环 那么,set集合有三个要点:1,可以去除重复的元素2,存取顺序不一致3,没有索引,不能用普......
  • 集合——Set系列
    (1)Set系列集合的特点1.无序、不重复、无索引2.Set集合的方法基本上与Collection的API一致(2)Set集合的实现类特点1.HashSet:无序、不重复、无索引2.LinkedHashSet:有序、不......
  • Set和multiset容器
     ......
  • 通过代码封装--set() get()方法实现需求
    /*通过代码封装,实现一下需求:\编写一个类Book,代表教材1.具有属性:名称(title)、页数(pageNum)2.其中的页数不能少于200页,否则输出错误信息,并赋予默认值200......
  • preparedStatement.setString()方法
    PreparedStatement作用:PreparedStatement是预编译的,对于批量处理可以大大提高效率.也叫JDBC存储过程。1、预编译sql语句,效率高2、安全,避免sql注入3、可以动态填充数据......
  • WebSocket连接失败
    ​  ​ 或​ 1.检查控件是否已经安装 如果没有安装,请下载安装:Word一键粘贴控件-控件包-泽优软件 注意提示窗口中的链接,   ​ 在chrome中启......