linux+apache服務器創建wss服務 https+wss配置指南


 在httpd.conf文件中,啟用 proxy_wstunnel_module 模塊

 LoadModule proxy_module modules/mod_proxy.so
 LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so

 

在ssl.conf文件中,配置SSL及代理

<VirtualHost _default_:443>

DocumentRoot "/var/www/html/welive"
ServerName gzmc168.cn
ServerAlias e.gzmc168.cn

ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

SSLEngine on

SSLProtocol all -SSLv2 -SSLv3

SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM

SSLCertificateFile /etc/httpd/ssl/gzmc168/e.gzmc168.cn_public.crt
SSLCertificateKeyFile /etc/httpd/ssl/gzmc168/e.gzmc168.cn.key
SSLCertificateChainFile /etc/httpd/ssl/gzmc168/e.gzmc168.cn_chain.crt
#這塊就是最主要的
SSLProxyEngine on 
ProxyRequests Off 
ProxyPass /wss ws://37.244.118.61:8430  #服務器+端口號
ProxyPassReverse /wss wss://e.gzmc168.cn/wss   #客戶端的域名

</VirtualHost>

 

客戶端js連接

// 證書是會檢查域名的,請使用域名連接
ws = new WebSocket("wss://e.gzmc168.cn/wss");

ws.onopen = function() {
alert("連接成功");
ws.send('tom');
alert("給服務端發送一個字符串:tom");
};
ws.onmessage = function(e) {
alert("收到服務端的消息:" + e.data);
};

記得重啟服務器

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM