2321321hhh 发表于 2017-1-13 16:24:09

Nginx1.10.1部署实战

1、系统信息


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# cat /etc/redhat-release
CentOS release 6.6 (Final)
# uname -r
2.6.32-504.el6.x86_64
# uname -m
x86_64
# uname -n
nginx-server
# ifconfig eth0
eth0      Link encap:EthernetHWaddr 00:0C:29:02:BD:AA
          inet addr:192.168.100.131Bcast:192.168.100.255Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe02:bdaa/64 Scope:Link
          UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
          RX packets:55736 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9189 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:77355420 (73.7 MiB)TX bytes:790859 (772.3 KiB)





2、软件信息

1
2
3
4
pcre:pcre-8.39.tar.gz
openssl:openssl-1.0.2a.tar.gz
zlib:zlib-1.2.7.tar.gz
nginx:nginx-1.10.1.tar.gz





3、环境准备

1
2
3
4
5
6
7
8
9
10
11
12
13
# mkdir /software
# ll -d /software/
drwxr-xr-x. 2 root root 4096 2017-01-12 16:04 /software/
# cd /software/
# yum -y install lrzsz gd-devel
# rz
# ll
total 8624
-rw-r--r--. 1 root root909077 2016-06-01 00:38 nginx-1.10.1.tar.gz
-rw-r--r--. 1 root root   29542 2015-04-03 10:42 nginx.vim
-rw-r--r--. 1 root root 5262089 2015-03-27 11:01 openssl-1.0.2a.tar.gz
-rw-r--r--. 1 root root 2062258 2016-09-26 15:01 pcre-8.39.tar.gz
-rw-r--r--. 1 root root560351 2015-03-27 10:49 zlib-1.2.7.tar.gz





4、安装pcre支持正则表达式

1
2
3
4
5
6
7
# tar xvfz pcre-8.39.tar.gz -C /usr/local/src/
# cd /usr/local/src/pcre-8.39/
# ./configure --prefix=/usr/local/pcre-8.39
# make && make install
# ln -s /usr/local/pcre-8.39/ /usr/local/pcre
# ll /usr/local/pcre
lrwxrwxrwx. 1 root root 21 2017-01-12 16:10 /usr/local/pcre -> /usr/local/pcre-8.39/





5、安装openssl支持加密访问

1
2
3
4
5
6
7
# tar xvfz openssl-1.0.2a.tar.gz -C /usr/local/src/
# cd /usr/local/src/openssl-1.0.2a/
# ./config --prefix=/usr/local/openssl-1.0.2a
# make && make install
# ln -s /usr/local/openssl-1.0.2a/ /usr/local/openssl
# ll /usr/local/openssl
lrwxrwxrwx. 1 root root 26 2017-01-12 16:17 /usr/local/openssl -> /usr/local/openssl-1.0.2a/





6、安装zlib支持压缩

1
2
3
4
5
6
7
# tar xvfz zlib-1.2.7.tar.gz -C /usr/local/src/
# cd /usr/local/src/zlib-1.2.7/
# ./configure --prefix=/usr/local/zlib-1.2.7
# make && make install
# ln -s /usr/local/zlib-1.2.7/ /usr/local/zlib
# ll /usr/local/zlib
lrwxrwxrwx. 1 root root 22 2017-01-12 16:19 /usr/local/zlib -> /usr/local/zlib-1.2.7/





7、安装nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# useradd -s /sbin/nologin -M www
# id www
uid=500(www) gid=500(www) groups=500(www)
# tar xvfz nginx-1.10.1.tar.gz -C /usr/local/src/
# cd /usr/local/src/nginx-1.10.1/
# ./configure \
--prefix=/usr/local/nginx-1.10.1 \
--sbin-path=/usr/local/nginx-1.10.1/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=www \
--group=www \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_image_filter_module \
--with-pcre=/usr/local/src/pcre-8.39/ \
--with-zlib=/usr/local/src/zlib-1.2.7 \
--with-openssl=/usr/local/src/openssl-1.0.2a
# make && make install
# ln -s /usr/local/nginx-1.10.1/ /usr/local/nginx
# ll /usr/local/nginx
lrwxrwxrwx. 1 root root 24 2017-01-12 16:35 /usr/local/nginx -> /usr/local/nginx-1.10.1/





8、配置文件支持语法检查

1
2
3
4
5
6
# mkdir-p ~/.vim/syntax
# mv /software/nginx.vim ~/.vim/syntax
# cat >> ~/.vim/filetype.vim<<EOF
> au BufRead,BufNewFile /etc/nginx/*,/usr/local/nginx/conf/vhost/* set ft=nginx
> EOF
注释:修改配置文件自由使用绝对路径才支持语法检查





9、编写控制脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# vim /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginxdaemin
#
# chkconfig:   -85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
#            proxy and IMAP/POP3 proxy server
# processname: nginx
# config:   /etc/nginx/nginx.conf
# pidfile:    /var/run/nginx/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ]&& exit 0

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
lockfile="/var/lock/nginx.lock"

start() {
    [ -x $nginx] || exit 5
    [ -f$NGINX_CONF_FILE ] || exit 6
    echo -n$"Starting $prog: "
    daemon$nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq0 ] && touch $lockfile
    return$retval
}

stop() {
    echo -n$"Stopping $prog: "
    killproc$prog -QUIT
    retval=$?
    echo
    [ $retval-eq 0 ] && rm -f $lockfile
    return$retval
}

restart() {
    configtest|| return $?
    stop
    start
}

reload() {
    configtest|| return $?
    echo -n$"Reloading $prog: "
    killproc$nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
$nginx -t -c$NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status>/dev/null 2>&1
}

case "$1" in
    start)
       rh_status_q && exit 0
      $1
      ;;
    stop)
       rh_status_q || exit 0
      $1
      ;;
   restart|configtest)
      $1
      ;;
    reload)
       rh_status_q || exit 7
      $1
      ;;
   force-reload)
       force_reload
      ;;
    status)
       rh_status
      ;;
   condrestart|try-restart)
       rh_status_q || exit 0
      ;;
    *)
      echo$"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
      exit 2
esac
# chmod +x /etc/init.d/nginx
# ll /etc/init.d/nginx
-rwxr-xr-x. 1 root root 1900 2017-01-12 16:41 /etc/init.d/nginx
# chkconfig --level 3 nginx on
# chkconfig --list|grep "nginx"
nginx         0:off   1:off   2:off   3:on    4:off   5:off   6:off





10、启动nginx服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# /etc/init.d/nginx start
Starting nginx:                                          
# netstat -tnlup|grep "80"
tcp      0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      27197/nginx
# ps -ef|grep "nginx"|grep -v "grep"
root   27197   10 16:45 ?      00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
www      27199 271970 16:45 ?      00:00:00 nginx: worker process
# curl http://127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
      width: 35em;
      margin: 0 auto;
      font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>



页: [1]
查看完整版本: Nginx1.10.1部署实战