下载所有包,jemalloc(可选)用于优化内存
yumgroupsinstall"DevelopmentTools"-y yum-yinstallbzip2 wget-cftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz wget-chttp://www.openssl.org/source/openssl-1.0.2g.tar.gz wget-chttp://www.zlib.net/zlib-1.2.11.tar.gz wget-chttp://tengine.taobao.org/download/tengine-2.1.2.tar.gz #wgethttp://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2 tar-zxfpcre-8.40.tar.gz-C/usr/local/src/ tar-zxfopenssl-1.0.2g.tar.gz-C/usr/local/src/ tar-zxfzlib-1.2.11.tar.gz-C/usr/local/src/ tar-zxftengine-2.1.2.tar.gz-C/usr/local/src/ #tarjxvfjemalloc-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 makeinstall
2、安装openssl
mkdir/usr/local/openssl cd/usr/local/src/openssl-1.0.2g/ ./config--prefix=/usr/local/openssl makedepend make-j makeinstall
vi /etc/profile
exportPATH=$PATH:/usr/local/openssl/bin or echo"exportPATH=$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 makeinstall
4、安装Nginx
groupaddwww useradd-gwwwwww-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 makeinstall
注意:--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-thisscriptstartsandstopstheNginxdaemon # #chkconfig:-8515 #description:NginxisanHTTP(S)server,HTTP(S)reverse\ #proxyandIMAP/POP3proxyserver #processname:Nginx #config:/etc/Nginx/Nginx.conf #config:/usr/local/Nginx/conf/Nginx.conf #pidfile:/usr/local/Nginx/logs/Nginx.pid #Sourcefunctionlibrary. ./etc/rc.d/init.d/functions #Sourcenetworkingconfiguration. ./etc/sysconfig/network #Checkthatnetworkingisup. ["$NETWORKING"="no"]&&exit0 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(){ #makerequireddirectories user=`$Nginx-V2>&1|grep"configurearguments:"|sed's/[^*]*--user=\([^]*\).*/\1/g'-` if[-z"`grep$user/etc/passwd`"];then useradd-M-s/bin/nologin$user fi options=`$Nginx-V2>&1|grep'configurearguments:'` foroptin$options;do if[`echo$opt|grep'.*-temp-path'`];then value=`echo$opt|cut-d"="-f2` if[!-d"$value"];then #echo"creating"$value mkdir-p$value&&chown-R$user$value fi fi done } start(){ [-x$Nginx]||exit5 [-f$Nginx_CONF_FILE]||exit6 make_dirs echo-n$"Starting$prog:" daemon$Nginx-c$Nginx_CONF_FILE retval=$? echo [$retval-eq0]&&touch$lockfile return$retval } stop(){ echo-n$"Stopping$prog:" killproc$prog-QUIT retval=$? echo [$retval-eq0]&&rm-f$lockfile return$retval } restart(){ #configtest||return$? stop sleep1 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/null2>&1 } case"$1"in start) rh_status_q&&exit0 $1 ;; stop) rh_status_q||exit0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q||exit7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q||exit0 ;; *) echo$"Usage:$0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit2 esac ############################################################ :wq!#保存退出 chmod775/etc/rc.d/init.d/Nginx#赋予文件执行权限 chkconfigNginxon#设置开机启动 /etc/rc.d/init.d/Nginxrestart#重启程序
在浏览器中打开服务器IP地址,会看到下面的界面,说明Nginx安装成功。
附./configure检测配置结果
# Configurationsummary +usingPCRElibrary:/usr/local/src/pcre-8.40 +usingOpenSSLlibrary:/usr/local/src/openssl-1.1.0e +md5:usingOpenSSLlibrary +sha1:usingOpenSSLlibrary +usingzliblibrary:/usr/local/src/zlib-1.2.11 +jemalloclibraryisdisabled#这个是我之前没有添加jemalloc内存优化的配置,这只是范例参考 Nginxpathprefix:"/usr/local/Nginx" Nginxbinaryfile:"/usr/local/Nginx/sbin/Nginx" Nginxconfigurationprefix:"/usr/local/Nginx/conf" Nginxconfigurationfile:"/usr/local/Nginx/conf/Nginx.conf" Nginxpidfile:"/usr/local/Nginx/logs/Nginx.pid" Nginxerrorlogfile:"/usr/local/Nginx/logs/error.log" Nginxhttpaccesslogfile:"/usr/local/Nginx/logs/access.log" Nginxhttpclientrequestbodytemporaryfiles:"client_body_temp" Nginxdsomodulepath:"/usr/local/Nginx/modules/" Nginxhttpproxytemporaryfiles:"proxy_temp" Nginxhttpfastcgitemporaryfiles:"fastcgi_temp" Nginxhttpuwsgitemporaryfiles:"uwsgi_temp" Nginxhttpscgitemporaryfiles:"scgi_temp"
扩展阅读:
Nginx配置txt、pdf、doc、xls等文件直接下载的方法
location / {
if ($request_filename ~* ^.*?\.(txt|pdf|doc|xls)$){
add_header Content-Disposition: 'attachment;';
}
}
参考:
http://www.osyunwei.com/archives/10057.html
http://blog.csdn.net/elong490/article/details/54913193
原文链接:https://www.f2er.com/centos/376885.html