当前位置:   article > 正文

在宝塔中nginx配置https

在宝塔中nginx配置https

在域名解析中配置证书

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

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

配置大致如下

  1. server
  2. {
  3. listen 80;
  4. listen 443;
  5. server_name wn789.xin www.wn789.xin;
  6. index index.php index.html index.htm default.php default.htm default.html;
  7. root /www/wwwroot/wn789.xin;
  8. if ($scheme = http ) { #http自动跳转到https
  9. return 301 https://$host$request_uri; #http自动跳转到https
  10. } #http自动跳转到https
  11. #error_page 404/404.html;
  12. error_page 404 /404.html;
  13. error_page 502 /502.html;
  14. ssl on; #需要添加
  15. ssl_certificate /etc/1_www.wn789.xin_bundle.crt; #需要添加(这里是你的.pem文件地址)
  16. ssl_certificate_key /etc/2_www.wn789.xin.key; #需要添加(这里是你的.key文件地址)
  17. ssl_session_timeout 5m; #需要添加
  18. ssl_protocols SSLv2 SSLv3 TLSv1; #需要添加
  19. ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; #需要添加
  20. ssl_prefer_server_ciphers on; #需要添加
  21. include enable-php-54.conf;
  22. include rewrite/wn789.xin.conf;
  23. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  24. {
  25. expires 30d;
  26. access_log on;
  27. }
  28. location ~ .*\.(js|css)?$
  29. {
  30. expires 12h;
  31. access_log on;
  32. }
  33. access_log /www/wwwlogs/wn789.xin.log;
  34. }

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

  1. # 本地调试模拟域名
  2. server{
  3. # gzip用来压缩前端文件体积
  4. gzip on;
  5. gzip_min_length 1024;
  6. gzip_buffers 4 16k;
  7. gzip_comp_level 9;
  8. 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;
  9. gzip_vary on;
  10. # 上传文件大小
  11. client_max_body_size 5m;
  12. listen 80;
  13. # 输入您的域名 t.fashop.cn 只为演示代码,如果您没有域名可以在本地的host里进行模拟,加一行 127.0.0.1 t.fashop.cn,这样就拦截了这个域名跳到本地项目,请尽可能的模拟线上环境
  14. server_name fa.ypyunedu.com;
  15. fastcgi_connect_timeout 300;
  16. fastcgi_send_timeout 300;
  17. fastcgi_read_timeout 300;
  18. # 映射到swoole端口
  19. location / {
  20. proxy_pass http://127.0.0.1:9510;
  21. proxy_redirect off;
  22. proxy_set_header Host $host;
  23. proxy_set_header X-Real-IP $remote_addr;
  24. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  25. proxy_http_version 1.1;
  26. proxy_set_header Upgrade $http_upgrade;
  27. proxy_set_header Connection "upgrade";
  28. proxy_connect_timeout 300s;
  29. proxy_send_timeout 300s;
  30. proxy_read_timeout 300s;
  31. }
  32. #我添加的配置开始
  33. listen 443;
  34. if ($scheme = http ) { #http自动跳转到https
  35. return 301 https://$host$request_uri; #http自动跳转到https
  36. } #http自动跳转到https
  37. ssl on; #需要添加
  38. ssl_certificate /etc/2284122_fa.ypyunedu.com.pem; #需要添加(这里是你的.pem文件地址)
  39. ssl_certificate_key /etc/2284122_fa.ypyunedu.com.key; #需要添加(这里是你的.key文件地址)
  40. ssl_session_timeout 5m; #需要添加
  41. ssl_protocols SSLv2 SSLv3 TLSv1; #需要添加
  42. ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; #需要添加
  43. ssl_prefer_server_ciphers on; #需要添加
  44. #我添加的配置结束
  45. # 上传资源
  46. location ~/Upload/.*\.(gif|jpg|jpeg|png|txt|mp3|mp4|rmvb|mkv|avi|mov|MOV|json|ico|css|js)$ {
  47. root /www/wwwroot/fashop/;
  48. }
  49. # 前端项目资源匹配
  50. location ~/manifest.json$ {
  51. root /www/wwwroot/fashop/a/;
  52. }
  53. # 前端项目资源匹配
  54. location ~/favicon.ico$ {
  55. root /www/wwwroot/fashop/a/;
  56. }
  57. # 前端项目资源匹配
  58. location ~/logo.png {
  59. root /www/wwwroot/fashop/a/;
  60. }
  61. # 前端项目资源匹配
  62. location ~/logo-black.png {
  63. root /www/wwwroot/fashop/a/;
  64. }
  65. # 前端项目资源匹配
  66. location ~/static/.*\.(gif|jpg|jpeg|png|txt|mp3|mp4|rmvb|mkv|avi|mov|MOV|json|ico|css|js)$ {
  67. root /www/wwwroot/fashop/a/;
  68. }
  69. # 前端项目资源匹配
  70. location ~(/a$|/a/) {
  71. root /www/wwwroot/fashop/;
  72. try_files $uri /a/index.html;
  73. }
  74. }

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

 

 

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/197336?site
推荐阅读
相关标签
  

闽ICP备14008679号