MQTT域名服务器安装配置

TAIDONG 2020-10-02 PM 2493℃ 0条

源码安装Nginx的 配置文件默认在 /usr/local/nginx/conf 里面的 nginx.conf文件!

./nginx - t : 表示检测 nginx.conf文件的语法是否有问题!
./nginx - s reload : 表示重新加载 nginx.conf文件!
./nginx - s quit : 表示强制或正常退出 Nginx 服务!
./nginx : 表示开启 Nginx 服务!

服务器配置;

yum update    //更新我们的 yum 源
yum -y install gcc automake autoconf libtool make    //安装 make工具
yum install gcc gcc-c++    //安装g++ 
yum install pcre pcre-devel  //安装pcre正则表达式,因为nginx的rewrite模块和http核心模块都是使用它
wget http://nginx.org/download/nginx-1.9.9.tar.gz  //获取 nginx
tar -vzxf nginx-1.9.9.tar.gz   //解压 nginx

cd nginx-1.9.9
./configure          //先使配置文件nginx生效

yum install zlib zlib-devel   //zlib提供压缩算法,nginx很多地方都会用到
yum install openssl openssl-devel   //用到安全页面,所以需要 OpenSSL库
wget https://codeload.github.com/openresty/headers-more-nginx-module/tar.gz/v0.33  //这个可以适配某些JS的webSocket协议头的库。解压tar -vzxf headers-more-nginx-module-0.33.tar.gz  可能需要直接访问域名下载,WinSCP工具上传

./configure --prefix=/usr/local/nginx --add-module=/root/nginx-1.9.9/headers-more-nginx-module-0.33 --with-http_stub_status_module --with-http_ssl_module  //添加模块openSSL和headers-more-nginx-module-0.33

make && make install   //开始编译nginx代码

cd /usr/local/nginx/sbin && ./nginx -V   //****emqttd在这个是目录****编译nginx代码后会有/usr/local/nginx目录,我们查看当前编译后有哪些模块生效了

wget https://www.emqx.io/downloads/broker/v2.3.11/emqttd-centos7-v2.3.11.zip  //获取emq压缩包
yum install unzip -y   //新增zip的解压工具,用来解压emq的压缩包
unzip emqttd-centos7-v2.3.11.zip  //解压压缩包emq

cd emqttd/bin 
./emqttd start    执行服务器emq

cd /usr/local/nginx/conf && vim nginx.conf   

-------------------------复制粘贴以下代码在http {}中---------------------------

server {
    listen 443;
    server_name mqtt.123456.cn;    #你的域名
    
    ssl on;
    ssl_certificate /root/myCert/cert/mqtt.123456.cn_chain.crt;      #这里是证书
    ssl_certificate_key /root/myCert/cert/mqtt.123456.cn_key.key;   #这里是秘钥
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;

    location / {
        root   html; 
        index  index.html index.htm;
    }

    location = /mqtt {
      
        # 8083就是我们的emq的websocket的端口号
        proxy_pass http://mqtt.123456.cn:8083;   #你的域名
        proxy_redirect off;
        proxy_set_header Host mqtt.123456.cn:8083;   #你的域名
        proxy_set_header Sec-WebSocket-Protocol mqtt;
        
        # 这个是与你的 js客户端的库有关系,本博文的不需要,为了兼顾以后小伙伴,我这里注释了下! 
        #more_clear_headers Sec-WebSocket-Protocol;

        # 这些都是 websocket必须要配置的
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        }
}

-------------------------其他---------------------------------------------------

cd /usr/local/nginx/sbin&& ./nginx -t       //查看配置文件语法有问题
cd /usr/local/nginx/sbin&& ./nginx -s reload   //重新加载配置文件   
标签: MQTT

非特殊说明,本博所有文章均为博主原创。

评论啦~


选择表情