2020年11月

Nginx或Apache通过反向代理配置wss服务

为不影响网站正常业务,使用 xx.com/wss 作为代理入口,即客户端连接地址为:wss://xx.com/wss

nginx配置:

server {
  listen 443;
 
  ssl on;
  ssl_certificate /etc/ssl/server.pem;
  ssl_certificate_key /etc/ssl/server.key;
  ssl_session_timeout 5m;
  ssl_session_cache shared:SSL:50m;
  ssl_protocols SSLv3 SSLv2 TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
 
  location /wss
  {
    proxy_pass http://127.0.0.1:2345;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header X-Real-IP $remote_addr;
  }
  
  # location / {} 站点的其它配置...
}

apache配置:
需开启proxy_wstunnel_module模块
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so

#extra/httpd-ssl.conf
DocumentRoot "/网站/目录"
ServerName 域名
 
# Proxy Config
SSLProxyEngine on
 
ProxyRequests Off
ProxyPass /wss ws://127.0.0.1:2345
ProxyPassReverse /wss ws://127.0.0.1:2345
 
# 添加 SSL 协议支持协议,去掉不安全的协议
SSLProtocol all -SSLv2 -SSLv3
# 修改加密套件如下
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on
# 证书公钥配置
SSLCertificateFile /server/httpd/cert/your.pem
# 证书私钥配置
SSLCertificateKeyFile /server/httpd/cert/your.key
# 证书链配置,
SSLCertificateChainFile /server/httpd/cert/chain.pem

trim汉字导致乱码解决

汉字trim时可能导致乱码,如:
trim("张三、李言、", "、");
解决:

/**
 * 中文trim 解决中文trim乱码
 * @param $string
 * @param string $trim_chars
 * @return string|string[]|null
 */
function mb_trim($string, $trim_chars = '\s'){
    return preg_replace('/^['.$trim_chars.']*(?U)(.*)['.$trim_chars.']*$/u', '\\1',$string);
}

layui table指定行变色 改变样式

done: function(res, curr, count){
    //进行表头样式设置
    $('th').css({'font-weight': 'bold', 'font-size': '15','color': 'orange','background':'linear-gradient(#f2f2f2,#cfcfcf)'});
    //遍历各行 处理样式等
    for(var i in res.data){
        //获取当前行数据
        var item = res.data[i];
        //如:ID等于1则复选框禁止选择
        if(item.id==1){
            $('tr[data-index=' + i + '] input[type="checkbox"]').prop('disabled', true); //禁用当前
            $('tr[data-index=' + i + '] input[type="checkbox"]').parent('div').css('display', 'none'); //隐藏这个复选框
            table.render('checkbox'); // 重新渲染一下checkbox
        }
        // 02.如果已结算则整行变灰色
        if(item.ck23=='ok'){
            $("tr[data-index='" + i + "']").attr({"style":"background:#cccccc"});
        }
        // …… 其他功能
    }
}