liunx7下centos6.8编译安装nginx1.12.1
来源:互联网 发布:淘宝天下 邀请 小二 编辑:程序博客网 时间:2024/06/05 03:58
正式开始前,编译环境gcc g++ 开发库之类的需要提前装好。
如果是ububtu平台初始安装编译安装则使用如下指令:
如果是centos则如下:
当没有make时:
安装make:
安装c++编译环境
yum -y install gcc-c++
下面正式开始
---------------------------------------------------------------------------
一般我们都需要先装pcre, zlib,openssl,前者为了重写rewrite,后者为了gzip压缩,在后者是为了使用ssl
1,选择源码包所存放的目录,这里为/usr/local/src
2,所有依赖的安装目录为/usr/local/related
安装pcre:
安装zlib
cd /usr/local/src
安装openssl
cd /usr/local/src
make
make install
安装它的时候或者安装mysql的依赖包bison 的时候都需要perl的支持所以:
cd /usr/local/src
wget http://www.cpan.org/src/5.0/perl-5.26.0.tar.gz
tar -zxf perl-5.26.0.tar.gz
./configure.gnu --prefix=/usr/local/related/pel
make && make install
最后安装nginx
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
如果编译pcre报如下错误:
yum -y install g++
安装完毕后重新编译pcre即可:
make clean
./configure --prefix=/usr/local/related/pcre
make && make install
nginx的编译选项:
make是用来编译的,它从Makefile中读取指令,然后编译。
make install是用来安装的,它也从Makefile中读取指令,安装到指定的位置。
configure命令是用来检测你的安装平台的目标特征的。它定义了系统的各个方面,包括nginx的被允许使用的连接处理的方法,比如它会检测你是不是有CC或GCC,并不是需要CC或GCC,它是个shell脚本,执行结束时,它会创建一个Makefile文件。nginx的configure命令支持以下参数:
--prefix=
定义一个目录,存放服务器上的文件 ,也就是nginx的安装目录。默认使用path
/usr/local/nginx。
--sbin-path=
设置nginx的可执行文件的路径,默认为path
.prefix
/sbin/nginx--conf-path=
设置在nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动,通过命令行中的-c选项。默认为path
.prefix
/conf/nginx.conf--pid-path=
path 设置nginx.pid文件,将存储的主进程的进程号。安装完成后,可以随时改变的文件名 , 在nginx.conf配置文件中使用 PID指令。默认情况下,文件名 为
.prefix
/logs/nginx.pid--error-log-path=
设置主错误,警告,和诊断文件的名称。安装完成后,可以随时改变的文件名 ,在nginx.conf配置文件中 使用 的error_log指令。默认情况下,文件名 为path
.prefix
/logs/error.log--http-log-path=
设置主请求的HTTP服务器的日志文件的名称。安装完成后,可以随时改变的文件名 ,在nginx.conf配置文件中 使用 的access_log指令。默认情况下,文件名 为path
.prefix
/logs/access.log--user=
设置nginx工作进程的用户。安装完成后,可以随时更改的名称在nginx.conf配置文件中 使用的 user指令。默认的用户名是nobody。name
--group=
设置nginx工作进程的用户组。安装完成后,可以随时更改的名称在nginx.conf配置文件中 使用的 user指令。默认的为非特权用户。name
--with-select_module
--without-select_module 启用或禁用构建一个模块来允许服务器使用select()方法。该模块将自动建立,如果平台不支持的kqueue,epoll,rtsig或/dev/poll。
--with-poll_module
--without-poll_module
启用或禁用构建一个模块来允许服务器使用poll()方法。该模块将自动建立,如果平台不支持的kqueue,epoll,rtsig或/dev/poll。--without-http_gzip_module
— 不编译压缩的HTTP服务器的响应模块。编译并运行此模块需要zlib库。--without-http_rewrite_module
不编译重写模块。编译并运行此模块需要PCRE库支持。--without-http_proxy_module
— 不编译http_proxy模块。--with-http_ssl_module
— 使用https协议模块。默认情况下,该模块没有被构建。建立并运行此模块的OpenSSL库是必需的。--with-pcre=
— 设置PCRE库的源码路径。PCRE库的源码(版本4.4 - 8.30)需要从PCRE网站下载并解压。其余的工作是Nginx的./ configure和make来完成。正则表达式使用在location指令和 ngx_http_rewrite_module 模块中。path
--with-pcre-jit
—编译PCRE包含“just-in-time compilation”(1.1.12中, pcre_jit指令)。--with-zlib=
—设置的zlib库的源码路径。要下载从 zlib(版本1.1.3 - 1.2.5)的并解压。其余的工作是Nginx的./ configure和make完成。ngx_http_gzip_module模块需要使用zlib 。path
--with-cc-opt=
— 设置额外的参数将被添加到CFLAGS变量。例如,当你在FreeBSD上使用PCRE库时需要使用:parameters
--with-cc-opt="-I /usr/local/include。
.如需要需要增加select()支持的文件数量
:--with-cc-opt="-D FD_SETSIZE=2048".
--with-ld-opt=
—设置附加的参数,将用于在链接期间。例如,当在FreeBSD下使用该系统的PCRE库,应指定:parameters
--with-ld-opt="-L /usr/local/lib".
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
最后设置nginx的开机自启动:
在/etc/init.d/ 下新建nginx文件并写入以下代码:
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# 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
# config: /etc/sysconfig/nginx
#pidfile: /usr/local/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/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/usr/local/nginx/lock/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -n "$user" ]; then
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
fi
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
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
sleep 1
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
}
#!/bin/sh
#
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
注意修改#pidfile,nginx,NGINX_CONF_FILE这三个所指定的路径为自己安装nginx时指定的,还要注意lockfile所指定的lock目录是否存在
写好后添加可执行权限
chmod a+x /etc/init.d/nginx
然后使用chkconfig --add nginx 来将nginx添加到系统管理中
添加完毕可使用chkconfig --list 来查看是否add成功
最后使用chkconfig nginx on 来设置开机启动
最后配置nginx.conf即可,请参阅下一篇博文
- liunx7下centos6.8编译安装nginx1.12.1
- liunx7下centos6.8编译安装mysql-5.7.18
- liunx7系统centos6.8版本编译安装php7
- centos6.4下安装nginx1.12.1
- Linux(CentOS6.5)下编译安装Nginx1.10.1
- Centos6.5编译安装Nginx1.8.0
- 编译安装 Nginx1.12.1
- CentOS6.5下Nginx1.7.4安装记录
- centos6.5下安装nginx1.8.0
- CentOS6.5下安装nginx1.10
- centOS6.5下yum安装nginx1.10.2
- CentOS6.5下Nginx1.7.4安装记录
- CentOS6.5下Nginx1.7.4安装记录
- centos6 编译nginx1.9.1
- CentOS6.3下编译安装配置nginx1.2.3+php5.3.16+mysql5.5.27+memcached1.4.5
- CentOS6.3下编译安装配置nginx1.2.3+php5.3.16+mysql5.5.27+memcached1.4.5
- CentOS6.4 64位下编译安装nginx1.5.11+php5.5.10+mariaDB5.5.36
- CentOS6.4下编译安装配置nginx1.2.3+php5.3.16+mysql5.5.27+memcached1.4.5
- ajax 有那些优缺点-如何解决跨域问题-ajax过程
- managed bean
- synchronized和volatile的区别
- 数据库中外键的作用以及和主键的区别
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution —— 异或
- liunx7下centos6.8编译安装nginx1.12.1
- Glide 加载图片 宽度固定 等比缩放
- MOOC程序设计与算法(二)第一周测验(2017夏季)特殊密码锁
- ubuntu 16.04 启用root用户方法
- HTTP协议(不是我总结的 哈哈哈哈 )
- 制作思维导图的技巧
- android uid 的定义
- 腾讯2017暑期实习生编程题--算法基础-字符移位
- unity脚本学习