centos7 源码安装nginx

 一.下载源码,安装依赖环境

安装依赖
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

cd /usr/local/software wget http://nginx.org/download/nginx-1.11.6.tar.gz tar -xvf nginx-1.11.6.tar.gz cd nginx-1.11.6

 

二、配置Nginx安装选项

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi 

编译安装
make && make install

查看编译情况
/usr/local/nginx/sbin/nginx -V

查看编译帮助
./configure  --help

 

三、启动、停止、重启

启动
/usr/local/nginx/sbin/nginx

停止
/usr/local/nginx/sbin/nginx -s stop

重新加载
/usr/local/nginx/sbin/nginx -s reload

nginx默认配置启动成功后,会有两个进程,一个主进程(守护进程),一个工作进程。主进程负责管理工作进程,工作进程负责处理用户的http请求。

 

四、配置nginx开机启动脚本

 vim /etc/init.d/nginx

#!/bin/bash
#chkconfig: - 85 15
PATH=/usr/local/nginx
DESC="nginx daemon"
NAME=nginx
DAEMON=$PATH/sbin/$NAME
CONFIGFILE=$PATH/conf/$NAME.conf
PIDFILE=$PATH/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
$DAEMON -s stop || echo -n "nginx not running"
}
do_reload() {
$DAEMON -s reload || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0

chmod a+x /etc/init.d/nginx

service nginx start | stop | reload | restart

 

vim /etc/rc.local加入一行

/etc/init.d/nginx start

 

五、使用nginx下载文件

nginx.conf添加如下内容

if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$)    {
    add_header Content-Disposition: 'attachment;';
}

 

 

 

posted @ 2018-05-03 16:06  走走~停停  阅读(136)  评论(0编辑  收藏  举报