首页 / NGINX / nginx-1.9.1安装
nginx-1.9.1安装
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了nginx-1.9.1安装,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4842字,纯文字阅读大概需要7分钟。
内容图文
操作系统 |
CentOS release 6.5 (Final) |
服务器IP |
192.168.1.200 |
nginx版本 |
nginx-1.9.1 |
pcre版本 |
8.30 |
openssl |
1.0.2a |
zlib |
1.2.7 |
源码包解压目录 |
/usr/local/src |
源码包安装目录 |
/usr/local/softname |
nginx安装目录 |
/usr/local/nginx-1.9.1/ |
安装前准备
[root@lb ~]# iptables -F ##清空防火墙
[root@lb ~]# iptables -X
[root@lb ~]# iptables -Z
[root@lb ~]# /etc/init.d/iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables: [确定]
[root@lb ~]# setenforce 0 ##临时关闭selinux
[root@lb ~]# sed -i ‘/SELINUX/s/enforcing/disabled/‘ /etc/selinux/config ##永久关闭selinux
[root@lb ~]# yum -y install vim ntpdate wget gcc gcc-c++ ##安装必要的软件
[root@lb ~]# ntpdate 0.pool.ntp.org ##同步时间服务器
[root@lb ~]# hwclock
安装pcre
[root@lb ~]# tar xvfz pcre-8.30.tar.gz -C /usr/local/src/
[root@lb ~]# cd /usr/local/src/pcre-8.30
[root@lb pcre-8.30]# ./configure --prefix=/usr/local/pcre-8.30
[root@lb pcre-8.30]# make && make install
安装openssl
[root@lb ~]# tar xvfz openssl-1.0.2a.tar.gz -C /usr/local/src/
[root@lb ~]# cd /usr/local/src/openssl-1.0.2a
[root@lb openssl-1.0.2a]# ./config --prefix=/usr/local/openssl-1.0.2a
[root@lb openssl-1.0.2a]# make && make install
安装zlib
[root@lb ~]# tar xvfz zlib-1.2.7.tar.gz -C /usr/local/src/
[root@lb ~]# cd /usr/local/src/zlib-1.2.7/
[root@lb zlib-1.2.7]# ./configure --prefix=/usr/local/zlib-1.2.7
[root@lb zlib-1.2.7]# make && make install
安装nginx
[root@lb ~]# groupadd www
[root@lb ~]# useradd -g www -s /sbin/nologin www
[root@lb ~]# tar xvfz nginx-1.9.1.tar.gz -C /usr/local/src/
[root@lb ~]# cd /usr/local/src/nginx-1.9.1/
[root@lb nginx-1.9.1]# ./configure \ ##编译安装
--prefix=/usr/local/nginx-1.9.1 \ ##指定nginx安装目录
--sbin-path=/usr/local/nginx-1.9.1/sbin/nginx \ ##可执行文件目录
--conf-path=/etc/nginx/nginx.conf \ ##主配置文件
--error-log-path=/var/log/nginx/error.log \ ##错误日志文件
--http-log-path=/var/log/nginx/access.log \ ##访问日志文件
--pid-path=/var/run/nginx/nginx.pid \ ##进程PID文件
--lock-path=/var/lock/nginx.lock \ ##锁文件
--user=www \ ##运行nginx非特权用户
--group=www \ ##运行nginx非特权用户组
--with-http_ssl_module \ ##支持https请求
--with-http_realip_module \ ##允许从请求标头更改客户端的IP地址值
--with-http_gzip_static_module \ ##在线实时压缩输出数据流
--with-http_stub_status_module \ ##获取Nginx自上次启动以来的工作状态
--with-pcre=/usr/local/src/pcre-8.30 \ ##pcre库文件目录,指源码解压目录
--with-zlib=/usr/local/src/zlib-1.2.7 \ ##zlib库文件目录,指源码解压目录
--with-openssl=/usr/local/src/openssl-1.0.2a ##openssl库文件目录,指源码解压目录
# make && make install
编写nginx控制脚本
[root@lb nginx-1.9.1]# vim /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# 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-1.9.1/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 -eq 0 ] && 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
[root@lb nginx-1.9.1]# chmod +x /etc/init.d/nginx
[root@lb nginx-1.9.1]# chkconfig nginx on
[root@lb nginx-1.9.1]# chkconfig --list | grep nginx
nginx 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@lb nginx-1.9.1]# /etc/init.d/nginx start
[root@lb nginx-1.9.1]# netstat -tnlp | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 29070/nginx
安装nginx.vim 使nginx配置文件支持语法检查
[root@lb nginx-1.9.1]# mkdir -p ~/.vim/syntax
[root@lb nginx-1.9.1]# mv /root/nginx.vim ~/.vim/syntax
[root@lb nginx-1.9.1]# cat >> ~/.vim/filetype.vim <<EOF
au BufRead,BufNewFile /etc/nginx/* set ft=nginx
EOF
本文出自 “所谓的命运 不同的选择” 博客,请务必保留此出处http://dongshi.blog.51cto.com/5145353/1718485
原文:http://dongshi.blog.51cto.com/5145353/1718485
内容总结
以上是互联网集市为您收集整理的nginx-1.9.1安装全部内容,希望文章能够帮你解决nginx-1.9.1安装所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。