nginx

###################nginx######################

1.nginx安裝

下載nginx-1.12.0.tar.gz安裝包

tar zxf nginx-1.12.0.tar.gz

 

[root@server3 nginx-1.12.0]# useradd -M -d /usr/local/lnmp/nginx -s /sbin/nologin -u 800  ##創建nginx用戶

 

[root@server3 nginx-1.12.0]# id nginx   ##查看用戶是否存在

uid=800(nginx) gid=800(nginx) groups=800(nginx)

 

[root@server3 nginx-1.12.0]# yum install -y gcc

 

[root@server3 nginx-1.12.0]# ./configure --prefix=/usr/local/lnmp/nginx --user=nginx --group=nginx --with-threads --with-file-aio --with-http_ssl_module --with-http_stub_status_module  ##添加模塊

 

根據添加模塊時的報錯安裝相關軟件

 

yum install pcre-devel -y

yum install opensll-devel -y

 

make && make install     ##編譯並進行安裝

[root@server3 ~]# netstat -antlp

Active Internet connections (servers and established)

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      12618/nginx

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      922/sshd

tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      998/master

tcp        0      0 172.25.6.3:22               172.25.6.250:37374          ESTABLISHED 1052/sshd

tcp        0      0 :::22                       :::*                        LISTEN      922/sshd

tcp        0      0 ::1:25                      :::*                        LISTEN      998/master

 

 

2.nginx虛擬主機

[root@server3 conf]# vim nginx.conf

wKioL1l4m96CLsFMAABI4epSlYo500.png-wh_50

[root@server3 /]# mkdir web1

mkdir: cannot create directory `web1': File exists

[root@server3 /]# cd web1/

[root@server3 web1]# ls

[root@server3 web1]# vim index.html

 <h1>server</h1>

測試:

wKiom1l4m-2gfDBdAAAdYiljQR4465.png-wh_50

3.  https

[root@server3 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.Qcb8J6'

-----

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) []:server3

Email Address []:[email protected]

[root@server3 certs]# ls

ca-bundle.crt        cert.pem         Makefile

ca-bundle.trust.crt  make-dummy-cert  renew-dummy-cert

[root@server3 certs]# mv cert.pem /usr/local/lnmp/nginx/conf/

[root@server3 certs]# nginx -s reload

測試:


wKiom1l4nAHDdN_mAAB6lj39d48433.png-wh_50

4.nginx訪問控制

[root@server3 certs]# cd /usr/local/lnmp/nginx/conf/

[root@server3 conf]# vim nginx.conf

wKioL1l4nA-zb4sGAABJWwcssA4677.png-wh_50

[root@server3 conf]# nginx -s reload

測試:

wKiom1l4nBzQN2nVAAAo3rMqghA976.png-wh_50

5.網頁重寫

wKioL1l4nCvBMar0AABLTNqmLY4660.png-wh_50

[root@server3 admin]# nginx -s reload

測試:

wKiom1l4nDviLhQrAAAdcUjL5K4771.png-wh_50

6.負載均衡()

wKiom1l4nEezZ8SHAABEFUsKTgw677.png-wh_50

wKioL1l4nFezz6mmAABEbxT8KG8650.png-wh_50

修改6.16.2主機的httpd的配置文件,將6.1的端口改爲80,將6.2的端口改爲8080,並重啓httpd使生效,如果火牆開啓,則關閉

測試:

wKiom1l4nGWy7ARlAAC0e9FmqSE950.png-wh_50

7.負載均衡(二)

wKiom1l4nHHxLkl9AAA6nJMLrsk771.png-wh_50

[root@server3 html]# nginx -t

nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful

[root@server3 html]# nginx  -s reload

打開6.3httpd,修改端口爲8000

如果6.16.2httpd正常

wKioL1l4nIbxTt_oAACHN5ifCmA057.png-wh_50

如果兩者掛掉

wKiom1l4nJiymPiVAADIu5GfMEI397.png-wh_50

8.負載均衡(三)

wKioL1l4nKuwpzkeAABdsE9jr9s023.png-wh_50

[root@server3 html]# nginx  -s reload

如果6.16.2正常

wKioL1l4nLmB5hg7AACMXasnA5c571.png-wh_50

如果6.1掛掉

wKioL1l4nMezYzyQAAB09puiHx4538.png-wh_50


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章