Contents
  1. 1. Install Nginx
    1. 1.1. Install Nginx Package
    2. 1.2. Install Nginx

Install Nginx

Install Nginx Package

1
2
3
4
5
6
[root@huoq bin]# yum install pcre pcre-devel -y
check by:
[root@huoq bin]# rpm -qa pcre pcre-devel
pcre-devel-8.32-15.el7_2.1.x86_64
pcre-8.32-15.el7_2.1.x86_64
[root@huoq tools]# yum install -y openssl-devel openssl

Install 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
wget http://nginx.org/download/nginx-1.6.3.tar.gz
useradd nginx -s /sbin/nologin -M
tar xf nginx-1.6.3.tar.gz
cd nginx-1.6.3/
./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.3 --with-http_stub_status_module --with-http_ssl_module
make
make install
ln -s /application/nginx-1.6.3 /application/nginx
vim /application/nginx/conf/nginx.conf
worker_processes 4;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log logs/access.log main;

sendfile on;

keepalive_timeout 65;

upstream web_pools {
server 127.0.0.1:8081;
server 127.0.0.1:8082;
}

server {
listen 80;
server_name localhost;

location / {
root html;
index index.html index.htm;
proxy_pass http://web_pools;
}
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
/application/nginx/sbin/nginx -t
vim /etc/init.d/nginx
#!/bin/bash
#
#chkconfig: - 85 15
#description: this script use to manage nginx process.
#

#set -x
. /etc/rc.d/init.d/functions

procnum=`ps -ef |grep "/application/nginx/sbin/nginx"|grep -v "grep"|wc -l`

start () {
if [ "$procnum" -eq 1 -a -f /application/nginx/logs/nginx.pid ]; then
echo -n "Starting nginx:"
success
echo
else
/application/nginx/sbin/nginx
if [ "$?" -eq 0 ]; then
echo -n "Starting nginx:"
success
echo
else
echo -n "Starting nginx:"
failure
echo
exit 4
fi
fi
}

stop () {
if [ "$procnum" -eq 1 -a -f /application/nginx/logs/nginx.pid ]; then
/application/nginx/sbin/nginx -s stop
if [ "$?" -eq 0 ]; then
echo -n "Stopping nginx:"
success
echo
else
echo -n "Stopping nginx:"
failure
echo
exit 3
fi
else
echo -n "Stopping nginx:"
success
echo
fi
}

case $1 in

start)
start
;;

stop)
stop
;;

restart)
stop
sleep 1
start
;;

reload)
if [ "$procnum" -eq 1 -a -f /application/nginx/logs/nginx.pid ]; then
/application/nginx/sbin/nginx -s reload
else
echo "nginx is not running!please start nginx first..."
exit 2
fi
;;

status)
if [ "$procnum" -eq 1 -a -f /application/nginx/logs/nginx.pid ]; then
echo "nginx is running..."
else
echo "nginx is not running..."
fi
;;

*)
echo "Usage : nginx [ start|stop|reload|restart|status ]"
exit 1
;;
esac
chmod +x /etc/init.d/nginx
chkconfig nginx on
/etc/init.d/nginx start
Starting nginx: [ OK ]
/etc/init.d/nginx status
nginx is running...

Written with StackEdit.

Contents
  1. 1. Install Nginx
    1. 1.1. Install Nginx Package
    2. 1.2. Install Nginx