Nginx网页重定向

nginx网页加密访问

[root@server1 ~]# cd /usr/local/lnmp/nginx/conf/
[root@server1 conf]# vim nginx.conf   ##修改配置文件
[root@server1 conf]# mkdir /www1
[root@server1 conf]# mkdir /www2
[root@server1 conf]# cd /www1
[root@server1 www1]# vim index.html
[root@server1 www1]# cat index.html
www.westos.org
[root@server1 www1]# cd /www2
[root@server1 www2]# vim index.html
[root@server1 www2]# cat index.html
www.linux.org

修改配置文件:
这里写图片描述
网页访问:
这里写图片描述
这里写图片描述

[root@server1 conf]# vim nginx.conf  ##编辑配置文件
[root@server1 conf]# nginx -s reload    ##检测失败
nginx: [emerg] BIO_new_file("/usr/local/lnmp/nginx/conf/cert.pem") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/usr/local/lnmp/nginx/conf/cert.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file)     

修改配置文件
这里写图片描述

root@server1 conf]# cd /etc/pki/
[root@server1 pki]# cd tls/
[root@server1 tls]# cd certs/
[root@server1 certs]# make cert.pem
umask 77 ; \
    PEM1=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
    PEM2=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
    /usr/bin/openssl req -utf8 -newkey rsa:2048 -keyout $PEM1 -nodes -x509 -days 365 -out $PEM2 -set_serial 0 ; \
    cat $PEM1 >  cert.pem ; \
    echo ""    >> cert.pem ; \
    cat $PEM2 >> cert.pem ; \
    rm -f $PEM1 $PEM2
Generating a 2048 bit RSA private key
............................+++
..........................................................................................................................+++
writing new private key to '/tmp/openssl.WkEe2d'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:cn
State or Province Name (full name) []:shaanxi
Locality Name (eg, city) [Default City]:xi'an
Organization Name (eg, company) [Default Company Ltd]:westos
Organizational Unit Name (eg, section) []:linux
Common Name (eg, your name or your server's hostname) []:server1
Email Address []:root@localhost
[root@server1 certs]# ll cert.pem 
[root@server1 certs]# cp cert.pem /usr/local/lnmp/nginx/conf/
[root@server1 certs]# cd /usr/local/lnmp/nginx/conf/
[root@server1 conf]# nginx -s reload   ##刷新成功

网页访问:https://www/westos/org
这里写图片描述
这里写图片描述

重定向

这里写图片描述
这里写图片描述

1.访问www.westos.org/index.html重定向到https://www.westos.org/index.html

[root@server1 conf]# vim nginx.conf
[root@server1 conf]# nginx -s reload

这里写图片描述
这里写图片描述

2.

[root@server1 conf]# cd /www2
[root@server1 www2]# vim index.html 
[root@server1 www2]# cat index.html 
bbs.westos.org
[root@server1 www2]# cd /usr/local/lnmp/nginx/conf/
[root@server1 conf]# vim nginx.conf
[root@server1 conf]# nginx -s reload

这里写图片描述

这里写图片描述

3.访问www.westos.org/bbs跳转到bbs.westos.or

[root@server1 conf]# vim nginx.conf
[root@server1 conf]# nginx -s reload

这里写图片描述
这里写图片描述

4.

[root@server1 conf]# cd /www1/
[root@server1 www1]# mkdir bbs
[root@server1 www1]# cd bbs/
[root@server1 bbs]# vim index.html
[root@server1 bbs]# cat index.html
www.westos.org - bbs

这里写图片描述
这里写图片描述

5.nginx重定向的IF条件判断

[root@server1 conf]# vim nginx.conf
[root@server1 conf]# nginx -s reload

这里写图片描述
这里写图片描述

猜你喜欢

转载自blog.csdn.net/Le_Anny/article/details/81484818