配备站点应用 https,而且将 http 跳转至 https。下列是nginx配备ssl资格证书布署的方式与Nginx配备HTTPS详细全过程。
1. nginx 的 ssl 控制模块安裝查询 nginx 是不是安裝 http_ssl_module 控制模块。
$ /usr/local/nginx/sbin/nginx -V
假如出現 configure arguments: --with-http_ssl_module, 则已安裝(下边的流程能够绕过,进到 nginx.conf 配备)。
免费下载 nginx 安裝包, nginx官方网站1.14.1平稳版本号tar.gz包。
# 免费下载安裝包到 src 文件目录
$ cd /usr/local/src $ wget download/nginx-1.14.1.tar.gz
缓解压力安裝包。
$ tar -zxvf nginx-1.14.1.tar.gz
配备 ssl 控制模块。
$ cd nginx-1.14.1 $ ./configure --prefix=/usr/local/nginx --with-http_ssl_module
应用 make 指令编译程序(应用make install会再次安裝nginx),这时当今文件目录会出現 objs 文档夹。
用新的 nginx 文档遮盖当今的 nginx 文档。
$ cp ./objs/nginx /usr/local/nginx/sbin/
再度查询安裝的控制模块(configure arguments: --with-http_ssl_module表明ssl控制模块已安裝)。
$ /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.14.1 ... configure arguments: --with-http_ssl_module2. ssl 资格证书布署
这儿应用的是阿里巴巴云的完全免费资格证书,限期为一年,申请办理详细地址(假如必须更长期的或是别的资格证书将会必须选购,这儿出示下阿里巴巴的特惠主题活动买东西车特惠卷(每满1000减50噢)~)。
免费下载申请办理好的 ssl 资格证书文档缩小包到当地并缓解压力(这儿是用的 pem 与 key 文档,文档名能够变更)。
在 nginx 文件目录在建 cert 文档夹储放资格证书文档。
$ cd /usr/local/nginx $ mkdir cert
将这2个文档提交至网络服务器的 cert 文件目录里。
这儿应用 mac 终端设备提交至网络服务器的 scp 指令(这儿必须新开业一个终端设备,不必应用联接网络服务器的对话框):
$ scp /Users/yourname/Downloads/ssl.pem [email protected]:/usr/local/nginx/cert/ $ scp /Users/yourname/Downloads/ssl.key [email protected]:/usr/local/nginx/cert/
scp [当地文档相对路径,能够立即拖文档至终端设备里边] [ 网络服务器登陆名 @ 网络服务器IP详细地址 : 网络服务器上的相对路径 ]
3. nginx.conf 配备编写 /usr/local/nginx/conf/nginx.conf 配备文档:
配备 https server。
注解掉以前的 http server 配备,增加 https server:
< index.htm; } }将 http 跳转 https
server { listen 80; server_name& ; return 301 pre>4. 重新启动 nginx
$ /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf假如 80 端口号被占有,用kill [id]来完毕过程:
# 查询端口号应用 $&stat -lntp Active& connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 21307/nginx: master tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3072/sshd tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 21307/nginx: master # 完毕 80 端口号过程 $ kill 21307再度重新启动 nginx :
$ /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf无信息内容提醒就取得成功啦~
标识: ssl配备 Nginx配备