温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

nginx中如何配置ssl证书

发布时间:2021-07-13 11:05:58 来源:亿速云 阅读:195 作者:Leah 栏目:大数据

nginx中如何配置ssl证书,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。



一,申请ssl证书
 我用的是腾讯晕的免费的ssl证书,申请成功后可以将证书下载下来,这是我下载解压后的文件,然后把它
nginx中如何配置ssl证书
二,上传ssl证书并配置
 选nginx文件夹里面的两个文件,然后通过xftp软件或其他方式上传到nginx的目录下,我选择了conf文件的那个目录
nginx中如何配置ssl证书
弄好之后开始配置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中如何配置ssl证书
然后进入到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,浏览网站
nginx中如何配置ssl证书
(如果你访问的网站的页面有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";
   }

关于nginx中如何配置ssl证书问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI