找回密码
 注册会员
搜索

本文来自

Linux

Linux

订阅|关注

请添加对本版块的简短描述

297

主题

314

帖子

2343

积分

管理员

Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20

积分
2343

[教程] WDCP配置Nginx给域名启用SSL证书教程

[复制链接]
跳转到指定楼层
楼主
42451 xiaoxiao 发表于 2015-3-21 17:42:28
本帖最后由 xiaoxiao 于 2015-4-4 23:12 编辑


首先在面板上按照常规方式创建网站,这里我创建了网站  dns.diledns.com
当网站创建成功后,在系统目录 /www/wdlinux/nginx/conf/vhost 下会生成站点的配置文件
切换到相关目录
  1. cd /www/wdlinux/nginx/conf/vhost
复制代码


使用 ls 命令查看相关站点配置文件,我这里生成的是 dns.diledns.com.conf
打开编辑
  1. vi dns.diledns.com.conf
复制代码


打开后默认的文件配置如下
  1. server {
  2.         listen       80;
  3.         server_name dns.diledns.com;
  4.         root /www/web/diledns/public_html;
  5.         index  index.html index.php index.htm;
  6.         error_page  400 /errpage/400.html;
  7.         error_page  403 /errpage/403.html;
  8.         error_page  404 /errpage/404.html;
  9.         location ~ \.php$ {
  10.                 proxy_pass http://127.0.0.1:88;
  11.                 include naproxy.conf;
  12.         }
  13.         location / {
  14.                 try_files $uri @apache;
  15.         }
  16.         location @apache {
  17.                  proxy_pass http://127.0.0.1:88;
  18.                  include naproxy.conf;
  19.         }
  20. }
复制代码


我们需要加入ssl的监听端口及证书文件的目录位置
主要是以下3项
listen       443 ssl;
ssl_certificate     /root/dns.diledns.com.crt;
ssl_certificate_key /root/dns.diledns.com.key;

加入ssl配置后的站点配置文件内容如下
  1. server {
  2.         listen       80;
  3.         listen       443 ssl;
  4.         server_name dns.diledns.com;
  5.         ssl_certificate     /root/dns.diledns.com.crt;
  6.         ssl_certificate_key /root/dns.diledns.com.key;
  7.         root /www/web/diledns/public_html;
  8.         index  index.html index.php index.htm;
  9.         error_page  400 /errpage/400.html;
  10.         error_page  403 /errpage/403.html;
  11.         error_page  404 /errpage/404.html;
  12.         location ~ \.php$ {
  13.                 proxy_pass http://127.0.0.1:88;
  14.                 include naproxy.conf;
  15.         }
  16.         location / {
  17.                 try_files $uri @apache;
  18.         }
  19.         location @apache {
  20.                  proxy_pass http://127.0.0.1:88;
  21.                  include naproxy.conf;
  22.         }
  23. }
复制代码


修改完成保存并重启nginx生效
  1. service nginxd restart
复制代码

回复

使用道具 举报

297

主题

314

帖子

2343

积分

管理员

Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20

积分
2343
沙发
 楼主|
xiaoxiao 发表于 2015-3-21 17:52:37
本帖最后由 xiaoxiao 于 2015-3-21 21:18 编辑


nginx服务器http重定向到https的正确写法
  1. server {
  2.   listen          80;
  3.   server_name    my.domain.com;
  4.   return          301 https://$server_name$request_uri;
  5. }

  6. server {
  7.   listen          443 ssl;
  8.   server_name    my.domain.com;

  9.   [....]
  10. }
复制代码



例如:
  1. server {
  2.         listen       80;
  3.         listen       443 ssl;
  4.         server_name www.hiss.tk www.hiss.tk;
  5.         ssl_certificate     /www/web/hiss/public_html/ssl/hiss.tk_bundle.crt;
  6.         ssl_certificate_key /www/web/hiss/public_html/ssl/hiss.tk.key;
  7. ...
复制代码


修改成
  1. server {
  2.         listen       80;
  3.         server_name www.hiss.tk www.hiss.tk;
  4.         return    301 https://$server_name$request_uri;
  5.         }
  6. server {
  7.         listen       443 ssl;
  8.         server_name www.hiss.tk www.hiss.tk;
  9.         ssl_certificate     /www/web/hiss/public_html/ssl/hiss.tk_bundle.crt;
  10.         ssl_certificate_key /www/web/hiss/public_html/ssl/hiss.tk.key;
  11. ...
复制代码

回复 支持 反对

使用道具 举报

快速回复 返回顶部 返回列表