lnmp之nginx


   Nginx是一款輕量級Web 服務器/反向代理服務器及電子郵件(IMAP/POP3)代理服務器,並在一個BSD-like 協議下發行。Nginx使用了最新的epoll(Linux 2.6內核)和kqueue(freebsd)網絡I/O模型,而Apache則使用的是傳統的select模型。目前Linux下能夠承受高併發訪問的 Squid、Memcached都採用的是epoll網絡I/O模型。

server3.example.com  172.25.85.3         

server4.example.com  172.25.85.4  
server5.example.com  172.25.85.5  


1.nginx原碼編譯:
tar zxf nginx-1.9.14.tar.gz


cd /root/nginx-1.9.14/auto/cc
vim gcc

# debug
#CFLAGS="$CFLAGS -g"


yum install pcre-devel  openssl-devel   -y
cd nginx-1.9.14
./configure --prefix=/usr/local/lnmp/nginx  --with-http_ssl_module  --with-http_stub_status_module   ##編譯成功
wKioL1eiIdzS3oJJAACDnfm1AvM419.png-wh_50

make
make install



cd /root
vim .bash_profile

PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/nginx/sbin

source .bash_profile


cd /usr/local/lnmp/nginx/sbin/
./nginx -t
./nginx
 curl -I localhost

useradd -s /sbin/nologin nginx
usermod -d /usr/local/lnmp/nginx/  nginx


cd  /etc/pki/tls/certs
make  cert.pem         ##生成了cert.pem
wKioL1eiIiKwtvCCAAA2l5ZKfFM285.png-wh_50
cp cert.pem /usr/local/lnmp/nginx/conf/
nginx -t
nginx -s reload

在網頁中訪問:http://server3.example.com    會生成這個key的相關信息



cd  /usr/local/lnmp/nginx/conf
vim nginx.conf

wKiom1eiIrmjYjHmAAAjTAYDkQo299.png-wh_50




wKioL1eiIrrzkWdLAAATItL3Qy4425.png-wh_50

wKiom1eiIrvB49PiAAAuqYXsMow534.png-wh_50

wKioL1eiIruxFovaAAASoBiFdU4157.png-wh_50

wKioL1eiIrzRbZ52AAAUzXKdYYM007.png-wh_50

user  nginx;
worker_processes  1;
events {
          use epoll;
    worker_connections  1024;
}
http {
        upstream westos{
           server 172.25.85.4:80;
           server 172.25.85.5:80;
 }
    include       mime.types;
    default_type  application/octet-stream;
 location / {
            root   html;
            index  index.html index.htm;
        }
        location /status {
             stub_status on;
             access_log off;
   }



 

server {
       listen       443 ssl;
       server_name  server3.example.com;
       ssl_certificate      cert.pem;
       ssl_certificate_key  cert.pem;
       ssl_session_cache    shared:SSL:1m;
       ssl_session_timeout  5m;
       ssl_ciphers  HIGH:!aNULL:!MD5;
       ssl_prefer_server_ciphers  on;
       location / {
           root   html;
           index  index.html index.htm;
       }
         }
server {
  listen 80;
  server_name   www.linux.org;
  location /{
          proxy_pass http://westos;
  }
}
server {
  listen 80;
  server_name   www.unix.org;
  location /{
                root /web2;
                index index.html;
  }
}



nginx  -t
nginx -s reload

172.25.85.4  server4.example.com
172.25.85.5  server5.example.com

在server4和server5上安裝httpd,並打開httpd
echo server4.example.com > /var/www/html/index.html
echo server5.example.com > /var/www/html/index.html


在物理機上作解析:
172.25.85.3  server3.example.com www.linux.org  www.unix.org





在網頁中打開www.linux.org 不停的刷新,server4.example.com 和 server5.example.com交替出現





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