下载所有包,jemalloc(可选)用于优化内存
yum groups install "Development Tools" -y yum -y install bzip2 wget -c ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz wget -c http://www.openssl.org/source/openssl-1.0.2g.tar.gz wget -c http://www.zlib.net/zlib-1.2.11.tar.gz wget -c http://tengine.taobao.org/download/tengine-2.1.2.tar.gz #wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2 tar -zxf pcre-8.40.tar.gz -C /usr/local/src/ tar -zxf openssl-1.0.2g.tar.gz -C /usr/local/src/ tar -zxf zlib-1.2.11.tar.gz -C /usr/local/src/ tar -zxf tengine-2.1.2.tar.gz -C /usr/local/src/ #tar jxvf jemalloc-3.6.0.tar.bz2 -C /usr/local/src/
1、安装pcre
mkdir /usr/local/pcre cd /usr/local/src/pcre-8.40 ./configure --prefix=/usr/local/pcre make -j make install
2、安装openssl
mkdir /usr/local/openssl cd /usr/local/src/openssl-1.0.2g/ ./config --prefix=/usr/local/openssl make depend make -j make install
vi /etc/profile
export PATH=$PATH:/usr/local/openssl/bin or echo "export PATH=$PATH:/usr/local/openssl/bin" >> /etc/profile
:wq!
source /etc/profile
3、安装zlib
mkdir /usr/local/zlib cd /usr/local/src/zlib-1.2.11 ./configure --prefix=/usr/local/zlib make -j make install
4、安装Nginx
groupadd www useradd -g www www -s /bin/false cd /usr/local/src/tengine-2.1.2/ #开启jemalloc内存优化 ./configure --prefix=/usr/local/Nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.2g --with-zlib=/usr/local/src/zlib-1.2.11 --with-pcre=/usr/local/src/pcre-8.40 --with-jemalloc=/usr/local/src/jemalloc-3.6.0 make make install
注意:--with-openssl=/usr/local/src/openssl-1.0.2g --with-zlib=/usr/local/src/zlib-1.2.11 --with-pcre=/usr/local/src/pcre-8.40指向的是源码包解压的路径,而不是安装的路径,否则会报错
5、添加开机启动脚本
/usr/local/Nginx/sbin/Nginx #启动Nginx 设置Nginx开机启动 vi /etc/rc.d/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: /usr/local/Nginx/conf/Nginx.conf # pidfile: /usr/local/Nginx/logs/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/sbin/Nginx" prog=$(basename $Nginx) Nginx_CONF_FILE="/usr/local/Nginx/conf/Nginx.conf" [ -f /etc/sysconfig/Nginx ] && . /etc/sysconfig/Nginx lockfile=/var/lock/subsys/Nginx make_dirs() { # make required directories user=`$Nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` 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 } 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 } 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 ############################################################ :wq! #保存退出 chmod 775 /etc/rc.d/init.d/Nginx #赋予文件执行权限 chkconfig Nginx on #设置开机启动 /etc/rc.d/init.d/Nginx restart #重启程序
在浏览器中打开服务器IP地址,会看到下面的界面,说明Nginx安装成功。
附./configure检测配置结果
# Configuration summary + using PCRE library: /usr/local/src/pcre-8.40 + using OpenSSL library: /usr/local/src/openssl-1.1.0e + md5: using OpenSSL library + sha1: using OpenSSL library + using zlib library: /usr/local/src/zlib-1.2.11 + jemalloc library is disabled #这个是我之前没有添加jemalloc内存优化的配置,这只是范例参考 Nginx path prefix: "/usr/local/Nginx" Nginx binary file: "/usr/local/Nginx/sbin/Nginx" Nginx configuration prefix: "/usr/local/Nginx/conf" Nginx configuration file: "/usr/local/Nginx/conf/Nginx.conf" Nginx pid file: "/usr/local/Nginx/logs/Nginx.pid" Nginx error log file: "/usr/local/Nginx/logs/error.log" Nginx http access log file: "/usr/local/Nginx/logs/access.log" Nginx http client request body temporary files: "client_body_temp" Nginx dso module path: "/usr/local/Nginx/modules/" Nginx http proxy temporary files: "proxy_temp" Nginx http fastcgi temporary files: "fastcgi_temp" Nginx http uwsgi temporary files: "uwsgi_temp" Nginx http scgi temporary files: "scgi_temp"
扩展阅读:
Nginx配置txt、pdf、doc、xls等文件直接下载的方法
location / {
if ($request_filename ~* ^.*?\.(txt|pdf|doc|xls)$){
add_header Content-disposition: 'p_w_upload;';
}
}
参考:
http://www.osyunwei.com/archives/10057.html
http://blog.csdn.net/elong490/article/details/54913193
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。