设为首页 收藏本站
查看: 595|回复: 0

[经验分享] Nginx1.10.1部署实战

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-1-13 16:24:09 | 显示全部楼层 |阅读模式
1、系统信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[iyunv@nginx-server ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[iyunv@nginx-server ~]# uname -r
2.6.32-504.el6.x86_64
[iyunv@nginx-server ~]# uname -m
x86_64
[iyunv@nginx-server ~]# uname -n
nginx-server
[iyunv@nginx-server ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:02:BD:AA
          inet addr:192.168.100.131  Bcast:192.168.100.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe02:bdaa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric: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
[iyunv@nginx-server ~]# mkdir /software
[iyunv@nginx-server ~]# ll -d /software/
drwxr-xr-x. 2 root root 4096 2017-01-12 16:04 /software/
[iyunv@nginx-server ~]# cd /software/
[iyunv@nginx-server software]# yum -y install lrzsz gd-devel
[iyunv@nginx-server software]# rz
[iyunv@nginx-server software]# ll
total 8624
-rw-r--r--. 1 root root  909077 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 root  560351 2015-03-27 10:49 zlib-1.2.7.tar.gz




4、安装pcre支持正则表达式
1
2
3
4
5
6
7
[iyunv@nginx-server software]# tar xvfz pcre-8.39.tar.gz -C /usr/local/src/
[iyunv@nginx-server software]# cd /usr/local/src/pcre-8.39/
[iyunv@nginx-server pcre-8.39]# ./configure --prefix=/usr/local/pcre-8.39
[iyunv@nginx-server pcre-8.39]# make && make install
[iyunv@nginx-server pcre-8.39]# ln -s /usr/local/pcre-8.39/ /usr/local/pcre
[iyunv@nginx-server pcre-8.39]# 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
[iyunv@nginx-server software]# tar xvfz openssl-1.0.2a.tar.gz -C /usr/local/src/
[iyunv@nginx-server software]# cd /usr/local/src/openssl-1.0.2a/
[iyunv@nginx-server openssl-1.0.2a]# ./config --prefix=/usr/local/openssl-1.0.2a
[iyunv@nginx-server openssl-1.0.2a]# make && make install
[iyunv@nginx-server openssl-1.0.2a]# ln -s /usr/local/openssl-1.0.2a/ /usr/local/openssl
[iyunv@nginx-server openssl-1.0.2a]# 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
[iyunv@nginx-server software]# tar xvfz zlib-1.2.7.tar.gz -C /usr/local/src/
[iyunv@nginx-server software]# cd /usr/local/src/zlib-1.2.7/
[iyunv@nginx-server zlib-1.2.7]# ./configure --prefix=/usr/local/zlib-1.2.7
[iyunv@nginx-server zlib-1.2.7]# make && make install
[iyunv@nginx-server zlib-1.2.7]# ln -s /usr/local/zlib-1.2.7/ /usr/local/zlib
[iyunv@nginx-server zlib-1.2.7]# 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
[iyunv@nginx-server software]# useradd -s /sbin/nologin -M www
[iyunv@nginx-server software]# id www
uid=500(www) gid=500(www) groups=500(www)
[iyunv@nginx-server software]# tar xvfz nginx-1.10.1.tar.gz -C /usr/local/src/
[iyunv@nginx-server software]# cd /usr/local/src/nginx-1.10.1/
[iyunv@nginx-server 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
[iyunv@nginx-server nginx-1.10.1]# make && make install
[iyunv@nginx-server nginx-1.10.1]# ln -s /usr/local/nginx-1.10.1/ /usr/local/nginx
[iyunv@nginx-server nginx-1.10.1]# 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
[iyunv@nginx-server nginx-1.10.1]# mkdir-p ~/.vim/syntax
[iyunv@nginx-server nginx-1.10.1]# mv /software/nginx.vim ~/.vim/syntax
[iyunv@nginx-server nginx-1.10.1]# 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
[iyunv@nginx-server nginx-1.10.1]# 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
[iyunv@nginx-server nginx-1.10.1]# chmod +x /etc/init.d/nginx
[iyunv@nginx-server nginx-1.10.1]# ll /etc/init.d/nginx
-rwxr-xr-x. 1 root root 1900 2017-01-12 16:41 /etc/init.d/nginx
[iyunv@nginx-server nginx-1.10.1]# chkconfig --level 3 nginx on
[iyunv@nginx-server nginx-1.10.1]# 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
[iyunv@nginx-server nginx-1.10.1]# /etc/init.d/nginx start
Starting nginx:                                            [  OK  ]
[iyunv@nginx-server nginx-1.10.1]# netstat -tnlup|grep "80"
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      27197/nginx
[iyunv@nginx-server nginx-1.10.1]# ps -ef|grep "nginx"|grep -v "grep"
root     27197     1  0 16:45 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
www      27199 27197  0 16:45 ?        00:00:00 nginx: worker process
[iyunv@nginx-server nginx-1.10.1]# 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、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-327997-1-1.html 上篇帖子: Nginx重新编译添加模块 下篇帖子: 大家都是怎么压测HTTPS的一起交流下
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表