nginx编译安装
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx编译安装相关的知识,希望对你有一定的参考价值。
Nginx编译安装
Linux系统下nginx的源码编译安装模块依赖性,需要依赖下面3个安装包(下面的演示版本不是最新版本,你也可以下载最新的版本,只要把版本号修改一下即可):
一般yum安装以下几个插件:
yum -y install pcre-devel zlib-devel openssl openssl-devel
但这里我们选择编译安装:
1:ssl 功能需要 openssl 库 ( 下载:http://www.openssl.org/source)
wget http://www.openssl.org/source/openssl-fips-1.0.2l.tar.gz
2:gzip 模块需要 zlib 库 ( 下载:http://www.zlib.net/)
wget http://zlib.net/zlib-1.2.11.tar.gz
3:rewrite 模块需要 pcre 库 ( 下载:http://www.pcre.org/ )
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
############## 一、安装OpenSSL ######################
下载地址 https://www.openssl.org/source/
wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz tar zxvf openssl-1.0.2l.tar.gz cd openssl-1.0.2l/ ./config --prefix=/usr/ --openssldir=/usr/ shared; make && sudo make install
################ 二、安装PCRE ########################
下载地址 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz tar zxvfpcre-8.41.tar.gz ./configure --prefix=/opt/pcre-8.41 ; make && sudo make install
################ 三、安装ZLIB ########################
tar -zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure make make install
################ 三、安装Nginx ########################
下载Nginx源码包(stable version)
wget http://nginx.org/download/nginx-1.12.2.tar.gz
创建用户与组:
groupadd nginx useradd -s /sbin/nologin -g nginx -M nginx
解压
tar -zxvf nginx-1.12.2.tar.gz cd nginx-1.12.2/
配置编译环境(--with-pcre、--with-openssl的路径是源码路径,pcre、openssl的安装路径在/opt,但这里只需要源码路径)
./configure --prefix=/opt/nginx --user=nginx --group=nginx --error-log-path=/opt/nginx/logs/nginx/error.log --http-log-path=/opt/nginx/logs/nginx/access.log --pid-path=/opt/nginx/run/nginx/nginx.pid --lock-path=/opt/nginx/var/lock/nginx.lock --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre=../pcre-8.41 --with-openssl (#编译路径指定--with-openssl=/opt/openssl-1.0.21)
#以上编译安装nginx后,--http-client-body-temp-path、--http-proxy-temp-path、--http-fastcgi-temp-path、--http-uwsgi-temp-path、--http-scgi-temp-path默认的路径就在/usr/local/nginx下,分别是client_body_temp、proxy_temp、fastcgi_temp、scgi_temp、uwsgi_temp
make && make install 添加一个nginx主程序的符号链接ln -s /web/nginx/sbin/nginx /usr/local/sbin/
配置参数描述:
--with-xxx 代表默认没有打开的功能
--without-xxx 代表默认打开的功能
--prefix=path 代表安装路径
--sbin-path=path sbin路径
--conf-path 配置文件
--pid-path 代表进程号保存文件
--error-log-path错误日志
--lock-path 锁文件
--user ps看到的启动进程用户
--group ps看到的启动进程用户所在组
--with-http_ssl_module
--with-http_flv_module
将nginx加入service来管理启动与停止:
vi /etc/init.d/nginx #!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.0.0.2 version. # chkconfig: - 85 15 # 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: /opt/nginx/conf/nginx.conf nginxd=/opt/nginx/sbin/nginx nginx_config=/opt/nginx/conf/nginx.conf nginx_pid=/opt/nginx/run/nginx/nginx.pid RETVAL=0 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 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /opt/nginx/run/nginx/nginx.pid #这里也要注意修改你的nginx的pid路径 } # reload nginx service functions. reload() { echo -n $"Reloading $prog: " 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 1 esac exit $RETVAL
chmo +x /etc/init.d/nginx chkconfig --add nginx chkconfig nginx on chkconfig --list nginx nginx 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
本文出自 “运维笔录 美玲” 博客,请务必保留此出处http://meiling.blog.51cto.com/6220221/1978442
以上是关于nginx编译安装的主要内容,如果未能解决你的问题,请参考以下文章