一、系统环境

1、系统:Ubuntu 16.04.2 LTS

2、WEB服务器:Openresty11.2.5

二、开始配置

1、获取certbot客户端

wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto

2、停止Nginx服务

sudo systemctl stop nginx.service

3、生成证书

./certbot-auto certonly --standalone --email `你的邮箱地址` -d `你的域名地址`

当前网站有多个域名时需在后面增加,例如:

./certbot-auto certonly --standalone --email `你的邮箱地址` -d `你的域名1` -d `你的域名2`

sudo ./certbot-auto  certonly --standalone --email "yourEmail@qq.com" -d "www.tinywan.com" 
-d "live.tinywan.com" -d "vod.tinywan.com" -d "livecdn.tinywan.com"
-d "nginx-vod.tinywan.com" -d "hls-auth.tinywan.com" -d "hls.tinywan.com" -d "auth.tinywan.com"

可能会出现错误1:OSError: Command /opt/eff.org/certbot/venv/bin/python2.7 - setuptools pkg_resources pip wheel failed with error code 2

通过搜索,找到了certbot的issue #issuecomment-273014451 ,原因是说,系统安装了多个版本的python,那么怎么删除呢?

解决办法:

apt-get purge python-virtualenv python3-virtualenv virtualenv
pip install virtualenv

可能会出现错误2:

Cleaning up challenges
Problem binding to port : Could not bind to IPv4 or IPv6.

解决:说明你的Nginx服务还在运行啊!赶紧的kill掉啊

成功生成证书的输出结果:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Obtaining a new certificate
Performing the following challenges:
tls-sni- challenge for www.tinywan.com
tls-sni- challenge for live.tinywan.com
tls-sni- challenge for vod.tinywan.com
tls-sni- challenge for livecdn.tinywan.com
tls-sni- challenge for nginx-vod.tinywan.com
tls-sni- challenge for hls-auth.tinywan.com
tls-sni- challenge for hls.tinywan.com
tls-sni- challenge for auth.tinywan.com
Waiting for verification...
Cleaning up challenges IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/www.tinywan.com-/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/www.tinywan.com-/privkey.pem
Your cert will expire on --. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again. To non-interactively renew *all* of your certificates, run
"certbot-auto renew"
- If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

4、查看生产的证书

tree /etc/letsencrypt/live/
www@TinywanAliYun:~$ sudo tree /etc/letsencrypt/live/
/etc/letsencrypt/live/
└── www.tinywan.top
├── cert.pem -> ../../archive/www.tinywan.top/cert1.pem
├── chain.pem -> ../../archive/www.tinywan.top/chain1.pem
├── fullchain.pem -> ../../archive/www.tinywan.top/fullchain1.pem
├── privkey.pem -> ../../archive/www.tinywan.top/privkey1.pem
└── README directory, files

5、编辑Nginx配置文件和开启SSL服务

sudo vim /usr/local/openresty/nginx/conf/nginx.conf

配置虚拟主机

...
  # 配置HTTP请求重定向
server {
listen ;
server_name www.tinywan.top;
rewrite ^ https://$http_host$request_uri? permanent; # force redirect http to https
}
# 配置SSL证书
server {
listen ssl;
     server_name www.tinywan.top;
        ssl_certificate /etc/letsencrypt/live/www.tinywan.top/fullchain.pem; 
ssl_certificate_key /etc/letsencrypt/live/www.tinywan.top//privkey.pem;
     #禁止在header中出现服务器版本,防止黑客利用版本漏洞攻击    
     server_tokens off;
set $root_path /home/www/web/golang;
root $root_path; location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$ last;
break;
}
}
}
...

6、重启Nginx服务

sudo systemctl restart nginx.service

7、Let’s Encrypt 生成的免费证书为3个月时间,使用Crontab可以无限次续签证书

# 每星期1的2点30分执行更新操作
* * /home/www/bin/certbot-auto renew >>/home/www/bin/logs/encrypt_auto_update.log >&

 遇到的坑,查边所有的地方都不能够解决,最后是内存不够用的问题?

OSError: Command /opt/eff.org/certbot/venv/bin/python2. - setuptools pkg_resources pip wheel failed with error code 

File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line , in create_environment

如何解决:

user@webserver:~$ sudo fallocate -l 1G /tmp/swapfile
user@webserver:~$ sudo chmod /tmp/swapfile
user@webserver:~$ sudo mkswap /tmp/swapfile
user@webserver:~$ sudo swapon /tmp/swapfile

最后记得释放掉分配的交换分区

user@webserver:~$ sudo swapoff /tmp/swapfile
user@webserver:~$ sudo rm /tmp/swapfile

Ubuntu 16.04更新遇到的错误:

Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
augeas-lenses is already the newest version (1.4.-0ubuntu1).
ca-certificates is already the newest version (20160104ubuntu1).
gcc is already the newest version (:5.3.-1ubuntu1).
libaugeas0 is already the newest version (1.4.-0ubuntu1).
libffi-dev is already the newest version (3.2.-).
python is already the newest version (2.7.-).
python-dev is already the newest version (2.7.-).
libssl-dev is already the newest version (1.0.2g-1ubuntu4.).
openssl is already the newest version (1.0.2g-1ubuntu4.).
python-virtualenv is already the newest version (15.0.+ds-3ubuntu1).
virtualenv is already the newest version (15.0.+ds-3ubuntu1).
upgraded, newly installed, to remove and not upgraded.
Creating virtual environment...
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/virtualenv.py", line , in <module>
main()
File "/usr/lib/python3/dist-packages/virtualenv.py", line , in main
symlink=options.symlink)
File "/usr/lib/python3/dist-packages/virtualenv.py", line , in create_environment
download=download,
File "/usr/lib/python3/dist-packages/virtualenv.py", line , in install_wheel
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
File "/usr/lib/python3/dist-packages/virtualenv.py", line , in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /root/.local/share/letsencrypt/bin/python2. - setuptools pkg_resources pip wheel failed with error code

解决办法:sudo apt install letsencrypt

国外教程:https://www.vultr.com/docs/setup-let-s-encrypt-with-lighttpd-on-ubuntu-16-04

Nginx 学习笔记(一)如何配置一个安全的HTTPS网站服务器的更多相关文章

  1. Nginx学习笔记二基本配置

    1.Nginx的配置文件默认在Nginx程序安装目录的conf二级目录下,主配置文件为nginx.conf.假设您的Nginx安装 在/usr/local/webserver/nginx/目录下,那么 ...

  2. nginx 学习笔记(2) nginx新手入门

    这篇手册简单介绍了nginx,并提供了一些可以操作的简单的工作.前提是nginx已经被安装到你的服务器上.如果没有安装,请阅读上篇:nginx 学习笔记(1) nginx安装.这篇手册主要内容:1. ...

  3. Nginx学习笔记之加强篇

    在上一篇文章Nginx学习笔记之应用篇中,我们已经可以正式运行自己的网站了.但是在使用Nginx服务器时还需要注意几个问题: 1.Nginx服务器上配置的单个站点的并发量不超过1024 2.Nginx ...

  4. Nginx学习笔记之应用篇

    Nginx服务器的安装请参考Nginx学习笔记之安装篇 关于Nginx配置文档的API在这里就不一一列出,现在我们来配置第一个Nginx架构实现负载均衡的网站. 1.打开IIS,配置如下站点 重复上述 ...

  5. Android(java)学习笔记219:开发一个多界面的应用程序之两种意图

    1.两种意图: (1)显式意图: 在代码里面用intent设置要开启Activity的字节码.class文件: (2)隐式意图: Android(java)学习笔记218:开发一个多界面的应用程序之人 ...

  6. Docker学习笔记之一,搭建一个JAVA Tomcat运行环境

    Docker学习笔记之一,搭建一个JAVA Tomcat运行环境 前言 Docker旨在提供一种应用程序的自动化部署解决方案,在 Linux 系统上迅速创建一个容器(轻量级虚拟机)并部署和运行应用程序 ...

  7. Nginx学习笔记4 源码分析

    Nginx学习笔记(四) 源码分析 源码分析 在茫茫的源码中,看到了几个好像挺熟悉的名字(socket/UDP/shmem).那就来看看这个文件吧!从简单的开始~~~ src/os/unix/Ngx_ ...

  8. 学习笔记_J2EE_SpringMVC_03_注解配置_@RequestMapping用法

    @RequestMappingde的用法 摘要: 主要介绍注解@RequestMapping的用法 一.@RequestMapping 简介 在Spring MVC 中使用 @RequestMappi ...

  9. Android:日常学习笔记(2)——分析第一个Android应用程序

    Android:日常学习笔记(2)——分析第一个Android应用程序 Android项目结构 整体目录结构分析 说明: 除了APP目录外,其他目录都是自动生成的.APP目录的下的内容才是我们的工作重 ...

随机推荐

  1. 虚拟机使用不同CPU配置时内存性能的差异

    第一款机器的配置: CPU(s): 8On-line CPU(s) list: 0-7Thread(s) per core: 1Core(s) per socket: 4座: 2NUMA 节点: 1 ...

  2. Oracle中rownum和rowid的理解

    rownum,rowid都叫伪列. 但是,rownum是逻辑上的编号,且其值总是从1开始,每行的rounum不是固定的.而rowid是“物理”编号.若数据库文件没有移动,则每行的 rowid一般是固定 ...

  3. 【转】CNN卷积神经网络_ GoogLeNet 之 Inception(V1-V4)

    http://blog.csdn.net/diamonjoy_zone/article/details/70576775 参考: 1. Inception[V1]: Going Deeper with ...

  4. 我的IntelliJ IDEA快捷键

    Ctrl + Alt + S    打开设置菜单 Ctrl + N    快速打开类,写类的全路径可以查看jar包中的类 Ctrl + Shift + N    快速打开文件 Ctrl + X     ...

  5. BZOJ3110[Zjoi2013]K大数查询——权值线段树套线段树

    题目描述 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c如果是2 a b c形式,表示询问从第a个位置到第b个位置,第C大的数是 ...

  6. BZOJ4378[POI2015]Logistyka——树状数组

    题目描述 维护一个长度为n的序列,一开始都是0,支持以下两种操作:1.U k a 将序列中第k个数修改为a.2.Z c s 在这个序列上,每次选出c个正数,并将它们都减去1,询问能否进行s次操作.每次 ...

  7. LightOJ - 1356 Prime Independence (二分图 最大独立集 素数打表)

    题意: 给你一个集合,让你从这个集合中挑选出几个数,使得这几个数中任意两个数相除后的值不能为素数 即挑选出来的这几个数不能互相冲突 最大独立集 = 所有点数 - 最大匹配数 呵..呵...原先用的二维 ...

  8. Codeforces Round #419 (Div. 2) B. Karen and Coffee

    To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...

  9. 树剖模板(洛谷P3384 【模板】树链剖分)(树链剖分,树状数组,树的dfn序)

    洛谷题目传送门 仍然是一个板子. 不过蒟蒻去学了一下BIT维护区间修改区间求和,常数果真十分优秀 设数列为\(a_i\),差分数组\(d_ i=a_ i-a_ {i-1}\),前缀和\(s_i=\su ...

  10. 【Luogu3803】多项式乘法FFT(FFT)

    题目戳我 一道模板题 自己尝试证明了大部分... 剩下的还是没太证出来... 所以就是一个模板放在这里 以后再来补东西吧.... #include<iostream> #include&l ...