linux nginx搭配https
微信小程序upload接口必須是https請求,所以就搭建https
一、Linux搭建https
1、申請ssl證書
這里用的是騰訊云提供的免費ssl.
https://console.qcloud.com/ssl?_ga=1.268456817.1619620622.1510718080
按照要求填寫信息,申請成功之后下載證書
2、修改nginx配置文件
將證書上傳到服務器上,解壓
然后到***/nginx/conf下修改nginx.conf文件
? ? ? 在最下面添加
? ? ? ?
server {listen 443 ssl;server_name 申請ssl證書的域名;ssl on;ssl_certificate 證書中crt文件地址;ssl_certificate_key 證書中key文件地址;ssl_session_cache shared:SSL:1m;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 / {proxy_pass http://127.0.0.1:項目端口/;proxy_set_header X-Forwared-For $remote_addr;proxy_set_header Host $host;}}然后保存退出,重啟nginx
ps -ef|grep nginx kill -9 xxxxxxxx ./ ***/nginx/sbin/nginx***nginx安裝路徑
一半情況下會報這個錯誤,這是由于nginx缺少http_ssl_module模塊,解決方案請參照https://www.cnblogs.com/ghjbk/p/6744131.html
*由于nginx是新搭建的,所以很多東西都沒有裝配,在執行./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_modul時候
會報錯誤:./configure: error: SSL modules require the OpenSSL library. You can either do not enable the module
解決方法:apt-get? install openssl??
apt-get install libssl-dev?
然后再執行就行了
?
3.啟動nginx
這里可以驗證https是否搭建成功
https://cloud.tencent.com/product/ssl?from=qcloudHpHeaderSsl
大功告成!吃個雞
二、如果項目使用的服務器添加了負載均衡,直接在負載上監聽443端口,上傳申請的ssl證書,配置一下nginx.conf文件,效果跟上面一樣,方法比較簡單,這里不具體描述
三、簡單配置nginx.conf
?
?
?
配置域名訪問,默認重定向指定頁面:rewrite
?
轉載于:https://www.cnblogs.com/SongG-blogs/p/8024633.html
總結
以上是生活随笔為你收集整理的linux nginx搭配https的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: *1408素数回文数的个数
- 下一篇: TouTiao开源项目 分析笔记10 实