最近上班的任務不多,就想著給自己的博客https://www.ttblog.site/添加一個ssl證書,以后使用https訪問,
因為我的服務是部署在centos上的,自己對linux的命令不是很熟悉,所以配置的時候遇到了不少問題,這里記錄一下自己配置的程序,
一,申請ssl證書
我用的是騰訊暈的免費的ssl證書,申請成功后可以將證書下載下來,這是我下載解壓后的檔案,然后把它
二,上傳ssl證書并配置
選nginx檔案夾里面的兩個檔案,然后通過xftp軟體或其他方式上傳到nginx的目錄下,我選擇了conf檔案的那個目錄
弄好之后開始配置conf里面的內容,一下是我的配置,我用的是nginx的1.18的版本,據說老的版本有些不一樣,這里給一個參考鏈接https://cloud.tencent.com/document/product/400/35244
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 443 default_server ssl ;
server_name www.tiantianboke.com;
ssl_certificate 1_www.tiantianboke.com_bundle.crt;
ssl_certificate_key 2_www.tiantianboke.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
#禁止在header中出現服務器版本,防止黑客利用版本漏洞攻擊
server_tokens off;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /api {
proxy_pass http://127.0.0.1:5000;
}
}
}
三,檢查nginx組態檔
配置并且保存完之后,使用nginx -t命令來檢查配置內容是否正常,如果出現
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:xxx,
這個時候就需要配置了,首先停止nginx運行
然后
find name configure
查找所configure在目錄
然后進入到nginx-1.18.0的目錄,執行
./configure --prefix=/usr/local/nginx --with-http_ssl_module //加上http模塊的ssl支持
然后執行
make
進行構建,不要執行make install
然后
cp objs/nginx /usr/local/nginx/sbin 覆寫之前的二進制檔案,
以上操作完成執行nginx -t就會看到組態檔沒有問題了,
然后重啟nginx,瀏覽網站
(如果你訪問的網站的頁面有http請求的話,那么url地址欄就會提示不安全,你要想辦法把他的http地址換為https)
但是我配置完成之后就發現我的頁面有問題了,signalr(服務端推送訊息到客戶端)這個js出現了跨域問題,然后我百度到的解決辦法就是
配置一下內容
location /chatHub { proxy_pass http://127.0.0.1:5000; proxy_http_version 1.1; #如果沒有這句,會產生409錯誤 proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }
以上只是配置我后端api的記錄程序,我的前端服務器配置的程序也和這差不多,配置的程序中也遇到了不少的問題,只是這幾個是印象最深的,以此記錄,僅做參考!
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/66468.html
標籤:Linux
上一篇:手把手搭建K3S+Rancher
