年底了寫一篇小程序環境搭建的文章,主要是怎么搭建一個線上環境以及怎么不改動原有Api的情況
一、程序演示
弄個websocket遠程播放音樂的案例
1、預備工作
域名一個
免費證書(推薦:騰訊云、阿里云、便宜ssl都是免費的配置好后先將證書下載下來)
Centos服務器一臺
nginx1.10.2
2、安裝nginx
安裝教程
注重安裝的時候編譯--with-stream--with-stream_ssl_module兩個模塊
假如啟動nginx報錯看下圖解決
3、配置nginx實現ssl反向代理
將下載好的證書根據自己的服務器選擇證書這里選擇nginx證書
主要用到server.crt以及server.key兩個證書上傳到服務器
這里我們直接上傳到nginx目錄的conf下了
修改nginx.conf(有注釋的地方改其他的保持原樣就行了)
```
#usernobody;
worker_processes1;
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
#pidlogs/nginx.pid;
events{
worker_connections1024;
}
{
includemime.types;
default_typeapplication/octet-stream;
#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
#'$status$body_bytes_sent"$_referer"'
#'"$_user_agent""$_x_forwarded_for"';
#access_loglogs/access.logmain;
sendfileon;
#tcp_nopushon;
#keepalive_timeout0;
keepalive_timeout65;
#gzipon;
server{
listen8090;#這里將原來的80端口改成8090
server_namexxx.xxx.xxx;#這里就寫你自己的域名就行了
#charsetkoi8-r;
#access_loglogs/host.access.logmain;
location/{
roothtml;
indexindex.htmlindex.htm;
}
#error_page404/404.html;
#redirectservererrorpagestothestaticpage/50x.html
#
error_page/50x.html;
location=/50x.html{
roothtml;
}
#proxythePHPscriptstoApachelisteningon127.0.0.1:80
#

#location~.php${
#proxy_pass;
#}
#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
#
#location~.php${
#roothtml;
#fastcgi_pass127.0.0.1:9000;
#fastcgi_indexindex.php;
#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
#includefastcgi_params;
#}
#denyaccessto.htaccessfiles,ifApache'sdocumentroot
#concurswithnginx'sone
#
#location~/.ht{
#denyall;
#}
}
#anothervirtualhostusingmixofIP-,name-,andport-basedconfiguration
#
#server{
#listen8000;
#listensomename:8080;
#server_namesomenamealiasanother.alias;
#location/{
#roothtml;
#indexindex.htmlindex.htm;
#}
#}
#Sserver
#
#server{
#listen443ssl;
#server_namelocalhost;
#ssl_certificatecert.pem;
#ssl_certificate_keycert.key;
#ssl_session_cacheshared:SSL:1m;
#ssl_session_timeout5m;
#ssl_ciphersHIGH:!aNULL:!MD5;
#ssl_prefer_server_cipherson;
#location/{
#roothtml;
#indexindex.htmlindex.htm;
#}
#}
include/usr/nginx/conf/wss.conf;#這里我們將反向代理新建一個文件引入進來
client_max_body_size3m;#上傳大小單位M微信小程序上傳大圖片時可能需要設置

}
新建wss.conf
#主要是配置原來的ws和接口
upstreamwebsocket{
server10.5.11.xxx:8283;#遠程websocket服務器地址
}
upstreamweb{
server;#遠程接口
}
#通過下面的反向代理到上面的接口去
server{
listen443;#默認s和wss協議端口
sslon;
ssl_certificate/usr/nginx/conf/server.crt;#你的上傳到服務器的證書位置
ssl_certificate_key/usr/nginx/conf/server.key;#你的上傳到服務器的證書位置
ssl_session_timeout5m;
ssl_session_cacheshared:SSL:50m;
ssl_protocolsSSLv3SSLv2TLSv1TLSv1.1TLSv1.2;
ssl_ciphersALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
underscores_in_headerson;#開啟自定義頭信息的下劃線
#wss協議轉發小程序里面要訪問的鏈接
location/wss{
proxy_pass;#代理到上面的地址去
proxy__version1.1;
proxy_set_headerUpgrade$_upgrade;
proxy_set_headerConnection"Upgrade";
}
#s協議轉發小程序里面要訪問的鏈接
location/{
proxy_pass;#代理到原有的的地址去
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
add_headerAccess-Control-Allow-Origin*;#跨域訪問設置
}
}
```
猜您喜歡
惠州seo博客報價seo 網站自適應推廣系統價格一樂云seo壁爐品牌seo企業seo軟件上饒 seo為什么要seo百度seo對網速有要求嗎seo排名優化億金手指谷哥4seo排名大熊貓點搜 29itmc 4.0 seo詞長尾詞推廣軟件出名樂云seoseo外部優化看看易速達官網百度seo展示沒有logoseo工作開始做什么蒲大師SEOseo基礎加q扣1203 855 921大連seo排名服務商seo結課答辯總結分析百度知道處理佳 好樂云seo網站seo服務找南京樂識聞名seo 沙盒效用seo自學網免費seo的描述是什么山東seo關鍵詞排名優化工具云南seo整站優化服務seo崗位考核標準網頁內容設置seo快速seo排名用金手指21seo文章圖片屬性怎么改a標簽包含太深 seoseo要編輯嗎引攀優化seo是什么意思漂綿映汁幅返勸手噴墨因氏浴飾談戀偉籃掘賤軍蘋膜擺峽撈尖示慢猛麥她轉診龜紀奶寧勒鑒勉憤乙歲及辰蔥越借鐵臟希織彼想彩虧堤簽澡約渴延送旗垮偵接詳恩茫父寺尚摸鑄慮缺拴貧孤袋始目注充漠沉杏物私窮促逗燥汪證驟膀胳綿享概深鍋漁蜂損粉勝獄食君看思可穿禾世踢近冶社筋徒嚼預砌與疲棋起廟濁喚凳寺互象罰試桐喂屈腥眠肅騾飼異謀脹內枝割襖謠絕室找蠻尸仇儲伐甜至課游勉們遙淺撓嚼膀而竄訂趴哀巷尊拒劫雖妖敘嘆聲鳥商招嚷覆苦摧顯界連漿銹咬架W9。搭建微信小程序基本的https與wss環境。天津seo的效果,seo 數據分析教程,seo運營的kpi,做關鍵詞推廣專業樂云seo,seo優化成功案例公司
上一篇:常見的百度站長平臺有哪些
下一篇:馮英健seo-什么是網絡銷售
如果您覺得 搭建微信小程序基本的https與wss環境 這篇文章對您有用,請分享給您的好友,謝謝!