nginx网页加密访问
[root@server1 ~]# cd /usr/local/lnmp/nginx/conf/
[root@server1 conf]# vim nginx.conf
123 server{
124 listen 80;
125 server_name www.westos.org;
126
127 location / {
128 root /www1;
129 index index.html;
130 }
131 }
132
133 server{
134 listen 80;
135 server_name www.linux.org;
136
137 location / {
138 root /www2;
139 index index.html;
140 }
141
142 }
[root@server1 conf]# mkdir /www1
[root@server1 conf]# mkdir /www2
[root@server1 conf]# cd /www1/
[root@server1 www1]# vim index.htmlwww.westos.org
[root@server1 www1]# cd /www2/
[root@server1 www2]# vim index.htmlwww.linux.org
[root@server1 www2]# cd /usr/local/lnmp/nginx/
[root@server1 nginx]# cd sbin/
[root@server1 sbin]# ./nginx -s reload
主机解析:
[root@foundation40 Desktop]# vim /etc/hosts172.25.40.1 www.westos.org bbs.westos.org www.linux.org
[root@server1 sbin]# cd /usr/local/lnmp/nginx/conf/
[root@server1 conf]# vim nginx.conf
105 server {
106 listen 443 ssl;
107 server_name www.westos.org;
108
109 ssl_certificate cert.pem;
110 ssl_certificate_key cert.pem;
111
112 ssl_session_cache shared:SSL:1m;
113 ssl_session_timeout 5m;
114
115 ssl_ciphers HIGH:!aNULL:!MD5;
116 ssl_prefer_server_ciphers on;
117
118 location / {
119 root /www1;
120 index index.html index.htm;
121 }
122 }
[root@server1 conf]# cd ..
[root@server1 nginx]# cd sbin/
[root@server1 sbin]# nginx -t
[root@server1 sbin]# cd /etc/pki
[root@server1 pki]# cd tls/
[root@server1 tls]# cd certs/
[root@server1 certs]# make cert.pemCountry Name (2 letter code) [XX]:cnState or Province Name (full name) []:shaanxiLocality Name (eg, city) [Default City]:xi'anOrganization Name (eg, company) [Default Company Ltd]:westosOrganizational Unit Name (eg, section) []:linuxCommon Name (eg, your name or your server's hostname) []:server1Email Address []:root@localhost
[root@server1 certs]# cp cert.pem /usr/local/lnmp/nginx/conf/
[root@server1 certs]# /usr/local/lnmp/nginx/sbin/nginx -t #检测
[root@server1 certs]# /usr/local/lnmp/nginx/sbin/nginx -s reload #刷新
网页重定向
1.访问westos.org跳转到www.westos.org
[root@server1 ~]# cd /usr/local/lnmp/nginx/conf/
[root@server1 conf]# vim nginx.conf
[root@server1 conf]# /usr/local/lnmp/nginx/sbin/nginx -s reload
2.访问www.westos.org/index.html重定向到https://www.westos.org/index.html
[root@server1 conf]# vim nginx.conf
[root@server1 conf]# /usr/local/lnmp/nginx/sbin/nginx -s reload
3.访问www.westos.org/bbs跳转到bbs.westos.org
[root@server1 conf]# cd /www2
[root@server1 www2]# vim index.html bbs.westos.org
[root@server1 conf]# vim nginx.conf
[root@server1 conf]# /usr/local/lnmp/nginx/sbin/nginx -s reload
4.
[root@server1 conf]# vim nginx.conf
[root@server1 conf]# /usr/local/lnmp/nginx/sbin/nginx -s reload
5.
[root@server1 conf]# cd /www1/
[root@server1 www1]# ls
index.html
[root@server1 www1]# mkdir bbs
[root@server1 www1]# cd bbs
[root@server1 bbs]# vim index.htmlwww.westos.org - bbs
[root@server1 bbs]# cd /usr/local/lnmp/nginx/conf/
[root@server1 conf]# vim nginx.conf
[root@server1 conf]# /usr/local/lnmp/nginx/sbin/nginx -s reload
6.nginx重定向的IF条件判断
[root@server1 conf]# vim nginx.conf
[root@server1 conf]# /usr/local/lnmp/nginx/sbin/nginx -s reload