版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xianglingchuan/article/details/82218428
Nginx升级支持stream模块
使用Nginx做tcp的反向代理,目前1.7至1.9版本需要加载[nginx_tcp_proxy_module]模块,1.9之后可以使用[with-stream]模块。
因为安装的时候使用的是LNMP(https://lnmp.org/),就采用了直接升级nginx的方法。
目录: lnmp1.5/include/upgrade_nginx.sh
注意执行该upgrade_nginx脚本时有以下模块的编译
–with-http_sub_module –with-stream –with-stream_ssl_module
编程完成后查看Nginx版本信息
[root@ffm ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.9.4
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2o 27 Mar 2018
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/chroot/bak/lnmp1.5/src/openssl-1.0.2o
单独Nginx下载地址:
http://nginx.org/download/
http://nginx.org/download/nginx-1.9.4.tar.gz
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;
}
}