1. 程式人生 > >Nginx網頁重定向

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 ##重新整理成功

重定向

這裡寫圖片描述
這裡寫圖片描述

[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

這裡寫圖片描述
這裡寫圖片描述