nginx配置ssl證書

最近上班的任務很少,就想着給本身的博客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/35244html

#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的記錄過程,個人前端服務器配置的過程也和這差很少,配置的過程當中也遇到了很多的問題,只是這幾個是印象最深的,以此記錄,僅作參考!linux

相關文章
相關標籤/搜索