博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在宝塔中nginx配置https
阅读量:3727 次
发布时间:2019-05-22

本文共 3343 字,大约阅读时间需要 11 分钟。

在域名解析中配置证书

等阿里云审核通过就可以去下载证书了

接下来就是宝塔配置环节了

配置大致如下

server{listen 80;listen 443;server_name wn789.xin www.wn789.xin;index index.php index.html index.htm default.php default.htm default.html;root /www/wwwroot/wn789.xin;if ($scheme = http ) { #http自动跳转到httpsreturn 301 https://$host$request_uri; #http自动跳转到https} #http自动跳转到https#error_page 404/404.html;error_page 404 /404.html;error_page 502 /502.html;ssl on; #需要添加ssl_certificate /etc/1_www.wn789.xin_bundle.crt; #需要添加(这里是你的.pem文件地址)ssl_certificate_key /etc/2_www.wn789.xin.key; #需要添加(这里是你的.key文件地址)ssl_session_timeout 5m;  #需要添加ssl_protocols SSLv2 SSLv3 TLSv1;  #需要添加ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;  #需要添加ssl_prefer_server_ciphers on;  #需要添加include enable-php-54.conf;include rewrite/wn789.xin.conf;location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)${expires 30d;access_log on;}location ~ .*\.(js|css)?${expires 12h;access_log on;}access_log /www/wwwlogs/wn789.xin.log;}

我的nginx配置被修改过了,也贴一份吧

# 本地调试模拟域名server{    # gzip用来压缩前端文件体积    gzip on;    gzip_min_length  1024;    gzip_buffers     4 16k;    gzip_comp_level 9;    gzip_types       text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/javascript;    gzip_vary on;    # 上传文件大小    client_max_body_size 5m;    listen       80;    # 输入您的域名 t.fashop.cn 只为演示代码,如果您没有域名可以在本地的host里进行模拟,加一行 127.0.0.1 t.fashop.cn,这样就拦截了这个域名跳到本地项目,请尽可能的模拟线上环境    server_name  fa.ypyunedu.com;    fastcgi_connect_timeout 300;    fastcgi_send_timeout 300;    fastcgi_read_timeout 300;    # 映射到swoole端口    location / {        proxy_pass http://127.0.0.1:9510;        proxy_redirect off;        proxy_set_header Host $host;        proxy_set_header X-Real-IP $remote_addr;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_http_version 1.1;        proxy_set_header Upgrade $http_upgrade;        proxy_set_header Connection "upgrade";        proxy_connect_timeout 300s;        proxy_send_timeout 300s;        proxy_read_timeout 300s;    }#我添加的配置开始	listen 443;	if ($scheme = http ) { #http自动跳转到httpsreturn 301 https://$host$request_uri; #http自动跳转到https} #http自动跳转到httpsssl on; #需要添加ssl_certificate /etc/2284122_fa.ypyunedu.com.pem; #需要添加(这里是你的.pem文件地址)ssl_certificate_key /etc/2284122_fa.ypyunedu.com.key; #需要添加(这里是你的.key文件地址)ssl_session_timeout 5m;  #需要添加ssl_protocols SSLv2 SSLv3 TLSv1;  #需要添加ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;  #需要添加ssl_prefer_server_ciphers on;  #需要添加#我添加的配置结束	    # 上传资源    location ~/Upload/.*\.(gif|jpg|jpeg|png|txt|mp3|mp4|rmvb|mkv|avi|mov|MOV|json|ico|css|js)$ {        root /www/wwwroot/fashop/;    }    # 前端项目资源匹配    location ~/manifest.json$ {         root /www/wwwroot/fashop/a/;    }    # 前端项目资源匹配    location ~/favicon.ico$ {          root /www/wwwroot/fashop/a/;    }    # 前端项目资源匹配    location ~/logo.png {          root /www/wwwroot/fashop/a/;    }    # 前端项目资源匹配    location ~/logo-black.png {          root /www/wwwroot/fashop/a/;    }    # 前端项目资源匹配    location ~/static/.*\.(gif|jpg|jpeg|png|txt|mp3|mp4|rmvb|mkv|avi|mov|MOV|json|ico|css|js)$ {        root /www/wwwroot/fashop/a/;    }    # 前端项目资源匹配    location ~(/a$|/a/) {        root /www/wwwroot/fashop/;        try_files $uri /a/index.html;    }}

放行443端口,重启nginx。就可以成功访问了

 

 

可以直接在面部中的ssl填写你生成好的证书即可

转载地址:http://lqtnn.baihongyu.com/

你可能感兴趣的文章
github下载的几种加速方法
查看>>
flutter杂记之时间格式化
查看>>
解决Flutter使用 Scaffold + Tabbar + TabbarView保存页面状态问题
查看>>
使用jpa的注解@query进行分页查询
查看>>
dart关于Named optional parameters can‘t start with an underscore的解决方法
查看>>
flutter实现一个自定义的LoadingDialog
查看>>
java之构造者模式demo
查看>>
flutter 对dio进行简单的二次封装
查看>>
flutter 对provider进行简单的二次封装
查看>>
java线程池之四种拒绝策略
查看>>
adb常用命令
查看>>
appium处理弹窗
查看>>
Activity的生命周期和启动模式
查看>>
kotlin杂记(一)
查看>>
Kotlin杂记之标准函数和静态方法
查看>>
kotlin杂记之延迟初始化和密封类
查看>>
Kotlin杂记之扩展函数和运算符重载
查看>>
Android广播机制
查看>>
Kotlin杂记之泛型和委托
查看>>
程序员是怎样玩植物大战僵尸的
查看>>