Linux.Centos6编译安装nginx
2024-10-18 20:21:37
环境
系统环境:CentOS release 6.7 (Final)
需求
centos6.7编译安装nginx1.x
准备
安装依赖
yum install -y gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel
下载安装包
cd /home/download
#download nginx
wget -c http://nginx.org/download/nginx-1.8.1.tar.gz
#download pcre
wget -c https://sourceforge.net/projects/pcre/files/pcre/8.35/pcre-8.35.tar.gz
#download zlib
wget -c http://zlib.net/zlib-1.2.8.tar.gz
#download openssl
wget -c http://www.openssl.org/source/openssl-1.0.1i.tar.gz
解压包
tar zxvf nginx-1.8..tar.gz tar zxvf pcre-8.35.tar.gz tar zxvf zlib-1.2..tar.gz tar zxvf openssl-1.0.1i.tar.gz
添加用户
groupadd -r nginx useradd -r -g nginx nginx
编译安装
cd /home/download/nginx-1.8. ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_realip_module \
--pid-path=/var/run/nginx.pid \
--with-pcre=/home/download/nginx/pcre-8.39 \
--with-zlib=/home/download/nginx/zlib-1.2. \
--with-openssl=/home/download/nginx/openssl-1.0.1i
make
make install
启动nginx
正确性检查
#每次修改nginx配置文件后都要进行检查
/usr/local/nginx/sbin/nginx -t
启动nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
下面添加一个脚本, 以方便控制nginx启动与停止
vi /etc/init.d/nginx
在文件中插入以下内容
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0. version.
# chkconfig: -
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit
[ -x $nginxd ] || exit
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;; *)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit
esac
exit $RETVAL
注意红色加粗部分,需要将路径改为自己机器的相应路径。
接着,设置文件的访问权限:
chmod a+x /etc/init.d/nginx (a+x参数表示 ==> all user can execute 所有用户可执行)
最后将ngix加入到rc.local文件中,这样开机的时候nginx就默认启动了
vi /etc/rc.local
添加
/etc/init.d/nginx start
保存并退出
下次重启就会生效,实现nginx的自启动。
最新文章
- SSL handshake alert: unrecognized_name error since upgrade to Java 1.7
- git 忽略提交某个指定的文件(不从版本库中删除)
- (转) Spring框架笔记(二十五)——NamedParameterJdbcTemplate与具名参数(转)
- [zt]OJ常见的Judge Status
- 还有人在用SQL Server 2000或2005吗? 2014来了!
- USACO Section 3.2 01串 Stringsobits
- orcale授权
- 【JSP&;Servlet学习笔记】4.会话管理
- 《ArcGIS Engine+C#实例开发教程》第四讲 状态栏信息的添加与实现
- win7下的vxworks总结
- [HttpException (0x80004005): Failed to Execute URL.]之画蛇添足之痛
- Asp.Net Identity 深度解析 之 注册登录的扩展
- POJ A Simple Problem with Integers 线段树 lazy-target 区间跟新
- javascript如何自动去除所有空格?
- ASP.NET Core 2.0 : 系列目录
- 如何最简便的利用Python实现数据可视化?当然离不开matplotlib!
- postgre的函数创建
- input 输入框 change 事件和 blur 事件
- (转载)C#:Form1_Load()不被执行的三个解决方法
- DevExpress WinForms v18.2新版亮点(八)