Nginx配置

tcp及ws的反向代理配置:
stream{
#tcp
upstream mqttserver{
#ip_hash;
server 192.168.1.117:18840 max_fails=1 fail_timeout=10s;
server 192.168.1.116:18840 max_fails=1 fail_timeout=10s;
}
server{
listen 18830;
proxy_connect_timeout 5s;
proxy_timeout 30s;
###proxy_timeout 24h;
###这个参数在使用EMQ压力测试时很有用,刚开始设备的超时时间过段,导致测试一小会儿就出现 {shutdown,connack_timeout}
proxy_pass mqttserver;
}

 #ws    
 upstream mqttws { 
    server  192.168.1.117:70830 weight=5 max_fails=1 fail_timeout=10s; 
    server  192.168.1.116:70830 weight=5 max_fails=1 fail_timeout=10s; 
 } 
 server
 {
     listen 8083;
     proxy_connect_timeout 5s;
     proxy_timeout 30s;         
     proxy_pass mqttws;     
 }      

}
但wss反向代理一直在stream中没有配置成功,但在http模块中配置成功了。
http{
wss反向代理配置
#wss
upstream httpmqttwss {
server 192.168.1.116:7084 weight=5 max_fails=1 fail_timeout=10s;
server 192.168.1.117:7084 weight=5 max_fails=1 fail_timeout=10s;
}

 server
 {
    listen  8084 ssl;
    #listen [::]:80 default_server ipv6only=on;
    server_name _;
    index index.html index.htm index.php;
    root  /home/wwwroot/default;

    #ssl on;
    ssl_certificate       /usr/local/ssl/web.com.pem;
    ssl_certificate_key   /usr/local/ssl/web.com.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    #ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
    ssl_prefer_server_ciphers on;    


    #error_page   404   /404.html;

    # Deny access to PHP files in specific directory
    #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; } 

    include enable-php.conf;
    location /mqtt {
       proxy_pass  https://httpmqttwss;
       proxy_read_timeout 60s;
       proxy_set_header Host $host;
       proxy_set_header X-Real_IP $remote_addr;
       proxy_set_header X-Forwarded-for $remote_addr;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection 'Upgrade';
    } 
    location /nginx_status
    {
        stub_status on;
        access_log   off;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }
    location ~ .*\.(js|css)?$
    {
        expires      12h;
    }
    location ~ /.well-known {
        allow all;
    }
    location ~ /\.
    {
        deny all;
    }
    access_log  /home/wwwlogs/access_ssl.log;
}    

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值