一、安全加密访问(安装需要编译ssl模块)
查看信息模块已经安装
二、编辑配置文件
[root@server1 nginx]# vim conf/nginx.conf
打开https server内的注释
三、生成证书
cd /etc/pki/tls/certs/ 证书生成存放位置再次目录下制作证书
[root@server1 certs]# cp cert.pem /usr/local/nginx/conf/ 复制证书到nginx的配置文件里面运行起来
[root@server1 certs]# cd /usr/local/nginx/conf
[root@server1 conf]# ls
【cert.pem】 fastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default
fastcgi.conf fastcgi_params koi-utf mime.types nginx.conf scgi_params uwsgi_params win-utf
[root@server1 conf]# mkdir /web 创建根目录
[root@server1 conf]# vim /web/index.html
[root@server1 nginx]# cat /web/index.html
https://www.westos.org
[root@server1 nginx]# ./sbin/nginx -t 语法检测
[root@server1 nginx]# ./sbin/nginx -s reload 刷新
编辑配置文件
四、客户端测试
[root@localhost ~]# vim /etc/hosts 添加解析
此设置只针对于www.westos.org访问时自动加密,其他域名访问不会自动添加https
五、重定向(不需手动添加https所有域名自动添加https)
更改之前的加密访问域名www.westos.org为localhost下面要重新使用www.westos.org
[root@server1 nginx]# vim conf/nginx.conf
[root@server1 nginx]# ./sbin/nginx -t
[root@server1 nginx]# ./sbin/nginx -s reload
临时重定向不缓存到本地
永久设定重定向
[root@server1 nginx]# vim conf/nginx.conf
[root@server1 nginx]# ./sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server1 nginx]# ./sbin/nginx -s reload
[root@server1 nginx]# mkdir /bbs
[root@server1 nginx]# cd /bbs
[root@server1 bbs]# vim index.html
<h1>bbs.westos.org</h1>