Nginx的web功能安裝

[root@web01 ~]# yum install pcre pcre-devel -y(下載依賴庫)

[root@web01 ~]# yum install openssl-devel -yhttps加密服務會用到)

[root@web01 ~]# rpm -qa pcre pcre-devel(檢查)

pcre-devel-7.8-7.el6.x86_64

pcre-7.8-7.el6.x86_64

[root@web01 ~]# rpm -qa openssl openssl-devel

openssl-devel-1.0.1e-42.el6.x86_64

openssl-1.0.1e-42.el6.x86_64

useradd nginx -M -s /sbin/nologin(建立虛擬用戶,-M不創建家目錄,不允許登錄)

id nginx(檢查虛擬用戶)

mkdir -p /application/tools(創建目錄)

cd /application/tools(切換目錄)

rz(上傳壓縮包,上傳到的目錄爲當前所在目錄)

tar xf nginx-1.6.3.tar.gz (解壓)

cd nginx-1.6.3

./configure --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module(初始化數據庫)

make && make install(編譯並安裝)

echo $?(檢驗編譯是否成功,輸出爲0表示正常,1爲不正常)

ln -s /application/nginx-1.6.3/ /application/nginx(創建軟連接,不要是用rm -rf刪除軟連接,會把軟連接下面的目錄刪除的)

[root@web01 ~]# /application/nginx/sbin/nginx -h(幫助文件)

nginx version: nginx/1.6.3

Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

 

Options:

  -?,-h         : this help

  -v            : show version and exit

  -V            : show version and configure options then exit

  -t            : test configuration and exit

  -q            : suppress non-error messages during configuration testing

  -s signal     : send signal to a master process: stop, quit, reopen, reload

  -p prefix     : set prefix path (default: /application/nginx-1.6.3/)

  -c filename   : set configuration file (default: conf/nginx.conf)

  -g directives : set global directives out of configuration file

[root@web01 ~]# /application/nginx/sbin/nginx -V(顯示編譯參數)

nginx version: nginx/1.6.3

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)

TLS SNI support enabled

configure arguments: --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module

[root@web01 ~]# cd /application/nginx/conf/(打開配置文件所在目錄)

egrep -v "#|^$" nginx.conf.default >nginx.conf(去掉雜項,nginx.conf.default文件爲nginx默認配置文件)

[root@web01 conf]# vim nginx.confd+G爲全部刪除光標以下內容)

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

        listen       80;

        server_name  www.etiantian.org;

        location / {

            root   html/www;

            index  index.html index.htm;

        }

    }

    server {

        listen       80;

        server_name  bbs.etiantian.org;

        location / {

            root   html/bbs;

            index  index.html index.htm;

        }

    }

    server {

        listen       80;

        server_name  blog.etiantian.org;

        location / {

            root   html/blog;

            index  index.html index.htm;

        }

    }

}

"nginx.conf" 35L, 764C 已寫入

mkdir -p ../html/{www,blog,bbs}(創建站點目錄文件)

for n in www bbs blog;do echo "$n.etiantian.org" > ../html/$n/index.html;done(創建主頁並寫入內容)

C:\Windows\System32\drivers\etc\hosts(物理機hosts添加下面解析)

10.0.0.8 www.etiantian.org etiantian.org blog.etiantian.org bbs.etiantian.org

以下爲簡化主配置文件

[root@web01 conf]# mkdir /application/nginx/conf/extra(建立extra目錄)

[root@web01 conf]# cat -n nginx.conf(查看行數)

     1  worker_processes  1;

     2  events {

     3      worker_connections  1024;

     4  }

     5  http {

     6      include       mime.types;

     7      default_type  application/octet-stream;

     8      sendfile        on;

     9      keepalive_timeout  65;

    10      server {

    11          listen       80;

    12          server_name  www.etiantian.org;

    13          location / {

    14              root   html/www;

    15              index  index.html index.htm;

    16          }

    17      }

    18      server {

    19          listen       80;

    20          server_name  bbs.etiantian.org;

    21          location / {

    22              root   html/bbs;

    23              index  index.html index.htm;

    24          }

    25      }

    26      server {

    27          listen       80;

    28          server_name  blog.etiantian.org;

    29          location / {

    30              root   html/blog;

    31              index  index.html index.htm;

    32          }

    33      }

    34  }

    35

[root@web01 conf]# sed -n '10,17p' nginx.conf >extra/www.conf(追加並創建各自站點配置文件)

[root@web01 conf]# cat extra/www.conf(檢查配置文件)

    server {

        listen       80;

        server_name  www.etiantian.org;

        location / {

            root   html/www;

            index  index.html index.htm;

        }

    }

[root@web01 conf]# sed -n '18,25p' nginx.conf >extra/bbs.conf

[root@web01 conf]# cat extra/bbs.conf

    server {

        listen       80;

        server_name  bbs.etiantian.org;

        location / {

            root   html/bbs;

            index  index.html index.htm;

        }

    }

[root@web01 conf]# sed -n '26,33p' nginx.conf >extra/blog.conf

[root@web01 conf]# cat extra/blog.conf

    server {

        listen       80;

        server_name  blog.etiantian.org;

        location / {

            root   html/blog;

            index  index.html index.htm;

        }

    }

[root@web01 conf]# vim nginx.conf(簡化主配置文件)

worker_processes  1;

error_log logs/error.log error;(指定錯誤日誌,相對路徑爲nginx安裝目錄,具體爲/application/nginx/logs/error.log

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '(日誌文件)

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

    #nginx vhosts config(各站點配置添加)

    include extra/www.conf;

    include extra/bbs.conf;

    include extra/blog.conf;

    include extra/status.conf;(檢查模塊)

}

~                                                                                                             

~                                                                                                             

[root@web01 conf]# cat >>/application/nginx/conf/extra/status.conf<<EOF(添加檢查模塊文件)

##status

server{

       listen       80;

       server_name       status.etiantian.org;

       location / {

         stub_status on;

         access_log off;

         }

    }

EOF

[root@web01 conf]# vim extra/www.conf

 

    server {

        listen       80;

        server_name  www.etiantian.org;

        location / {

            root   html/www;

            index  index.html index.htm;

        }

        access_log logs/access_www.log main;(在單獨標籤中添加日誌文件,好區分)

    }

[root@web01 conf]# /application/nginx/sbin/nginx -t(檢查語法)

nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful

[root@web01 conf]# /application/nginx/sbin/nginx -s reload(重啓服務)

[root@web01 conf]# netstat -lntup|grep nginx(檢查服務是否運行)

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      14049/nginx        

[root@web01 html]# vim /etc/rc.local(開機自啓動)

 

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

 

touch /var/lock/subsys/local

/etc/init.d/rpcbind start

/application/nginx/sbin/nginx

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

"/etc/rc.local" 11L, 404C 已寫入                                                              

wKiom1ZdaN-DqmkaAAKp0ylifTk489.png

按天輪詢切割腳本,需要放入crontab中做定時任務

/bin/date +%F -d -1day

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