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;
}
}