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