安装traefik
- 选择版本下载
1 | $ wget https://github.com/containous/traefik/releases/download/v1.7.9/traefik |
- 添加执行权限与全局访问
1 | $ chmod 755 traefik |
简单配置
- 创建配置文件
1 | $ touch traefik.toml |
- 配置信息
1 | logLevel = "INFO" |
- 注意:
a.com为 certbot 生成证书时的第一个-d参数certFile对应certbot生成的fullchain.pem目录,keyFile对应certbot生成的privkey.pem目录,
rules.toml 创建与配置
- 在 traefik.toml 同一目录下创建
1 | $ touch rules.toml |
- 简要配置
1 | [backends] |
运行
1 | $ traefik -c traefik.toml & |
- 注:
&为后台运行
关闭
- 查看端口
1 | $ ps -ef | grep traefik |
- 关闭traefik
1 | $ kill -9 [端口号] |
安装certbot
系统: centos7
- 安装yum-utils
1 | $ yum -y install yum-utils |
- certbot安装
1 | $ sudo yum install certbot |
- 错误解决
1 | No module named 'requests.packages.urllib3 |
- 使用方法(注意:
需要关闭web服务,注意证书生成与方向代理工具的https配置顺序)
1、生成证书
1 | $ sudo certbot certonly --standalone -d [域名1(a.com)] -d [域名2(www.a.com)] |
生成的文件目录为 /etc/letsencrypt/live/a.com/(最后一个文件名字由第一个 -d 的参数决定)
2、重新生成
1 | $ sudo certbot renew |
wordpress https访问时http资源无法访问
- wordpress项目根目录下的wp-config.php中添加以下代码
注意填写位置不要为最底部
1 | if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |