nginx中如何配置ssl证书,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
创新互联建站是一家专注于成都做网站、网站制作与策划设计,墨玉网站建设哪家好?创新互联建站做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:墨玉等地区。墨玉做网站价格咨询:13518219792
一,申请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";
}关于nginx中如何配置ssl证书问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。
当前题目:nginx中如何配置ssl证书
本文网址:http://www.jxjierui.cn/article/ihpdjs.html


咨询
建站咨询
