一、软件配置信息
CentOS 6.5
二、必要软件准备
检查安装pcre,openssl,gzip命令如下:
yuminstall-yzlibzlib-develpcrepcre-developensslopenssl-devel
[root@localhostsrc]#groupaddNginx [root@localhostsrc]#useradd-r-gNginx-s/sbin/nologin-MNginx
四、下载解压
Nginx可以从官网下载:http://Nginx.org/
也可以通过命令直接下载,我的当前目录是/usr/local/src:
[root@localhostsrc]#wgethttp://Nginx.org/download/Nginx-1.10.1.tar.gz
解压:
[root@localhostsrc]#tarzxvfNginx-1.10.1.tar.gz [root@localhostsrc]#cdNginx-1.10.1
五、开始安装
[root@localhostsrc]#cdNginx-1.6.3 [root@localhostNginx-1.6.3]#./configure--prefix=/usr/local/Nginx--sbin-path=/usr/sbin/Nginx--conf-path=/usr/local/Nginx/conf/Nginx.conf--error-log-path=/var/log/Nginx/error.log--http-log-path=/var/log/Nginx/access.log--pid-path=/var/run/Nginx.pid--lock-path=/var/run/Nginx.lock--http-client-body-temp-path=/var/cache/Nginx/client_temp--http-proxy-temp-path=/var/cache/Nginx/proxy_temp--http-fastcgi-temp-path=/var/cache/Nginx/fastcgi_temp--http-uwsgi-temp-path=/var/cache/Nginx/uwsgi_temp--http-scgi-temp-path=/var/cache/Nginx/scgi_temp--user=Nginx--group=Nginx--with-http_ssl_module--with-http_realip_module--with-http_addition_module--with-http_sub_module--with-http_dav_module--with-http_flv_module--with-http_mp4_module--with-http_gunzip_module--with-http_gzip_static_module--with-http_random_index_module--with-http_secure_link_module--with-http_stub_status_module--with-http_auth_request_module--with-file-aio--with-http_spdy_module--with-ipv6--with-pcre ./configure\ --prefix=/usr/local/Nginx\ --sbin-path=/usr/sbin/Nginx\ --conf-path=/usr/local/Nginx/conf/Nginx.conf\ --error-log-path=/var/log/Nginx/error.log\ --http-log-path=/var/log/Nginx/access.log\ --pid-path=/var/run/Nginx.pid\ --lock-path=/var/run/Nginx.lock\ --http-client-body-temp-path=/var/cache/Nginx/client_temp\ --http-proxy-temp-path=/var/cache/Nginx/proxy_temp\ --http-fastcgi-temp-path=/var/cache/Nginx/fastcgi_temp\ --http-uwsgi-temp-path=/var/cache/Nginx/uwsgi_temp\ --http-scgi-temp-path=/var/cache/Nginx/scgi_temp\ --user=Nginx\ --group=Nginx\ --with-http_ssl_module\ --with-http_realip_module\ --with-http_addition_module\ --with-http_sub_module\ --with-http_dav_module\ --with-http_flv_module\ --with-http_mp4_module\ --with-http_gunzip_module\ --with-http_gzip_static_module\ --with-http_random_index_module\ --with-http_secure_link_module\ --with-http_stub_status_module\ --with-http_auth_request_module\ --with-file-aio\ --with-http_spdy_module\ --with-ipv6\ --with-pcre [root@localhostNginx-1.6.3]#make [root@localhostNginx-1.6.3]#makeinstall
六、启动停止
启动命令:
[root@localhostNginx-1.6.3]#/usr/sbin/Nginx
测试,直接用curl命令读取web信息:
[root@localhostsbin]#curl-shttp://localhost|grepNginx.com
关闭命令:
[root@localhostNginx-1.6.3]#/usr/sbin/Nginx-sstop reload,当你修改配置时,用此命令不用再重启就生效了: [root@localhostNginx-1.6.3]#/usr/sbin/Nginx-sreload
vi/etc/init.d/Nginx #!/bin/sh # #NginxStartupscriptforNginx # #chkconfig:-8515 #processname:Nginx #config:/etc/Nginx/Nginx.conf #config:/etc/sysconfig/Nginx #pidfile:/var/run/Nginx.pid #description:NginxisanHTTPandreverseproxyserver # ###BEGININITINFO #Provides:Nginx #required-Start:$local_fs$remote_fs$network #required-Stop:$local_fs$remote_fs$network #Default-Start:2345 #Default-Stop:016 #Short-Description:startandstopNginx ###ENDINITINFO #Sourcefunctionlibrary. ./etc/rc.d/init.d/functions if[-L$0];then initscript=`/bin/readlink-f$0` else initscript=$0 fi sysconfig=`/bin/basename$initscript` if[-f/etc/sysconfig/$sysconfig];then ./etc/sysconfig/$sysconfig fi Nginx=${Nginx-/usr/sbin/Nginx} prog=`/bin/basename$Nginx` conffile=${CONFFILE-/etc/Nginx/Nginx.conf} lockfile=${LOCKFILE-/var/lock/subsys/Nginx} pidfile=${PIDFILE-/var/run/Nginx.pid} SLEEPMSEC=${SLEEPMSEC-200000} UPGRADEWAITLOOPS=${UPGRADEWAITLOOPS-5} RETVAL=0 start(){ echo-n$"Starting$prog:" daemon--pidfile=${pidfile}${Nginx}-c${conffile} RETVAL=$? echo [$RETVAL=0]&&touch${lockfile} return$RETVAL } stop(){ echo-n$"Stopping$prog:" killproc-p${pidfile}${prog} RETVAL=$? echo [$RETVAL=0]&&rm-f${lockfile}${pidfile} } reload(){ echo-n$"Reloading$prog:" killproc-p${pidfile}${prog}-HUP RETVAL=$? echo } upgrade(){ oldbinpidfile=${pidfile}.oldbin configtest-q||return echo-n$"Startingnewmaster$prog:" killproc-p${pidfile}${prog}-USR2 echo foriin`/usr/bin/seq$UPGRADEWAITLOOPS`;do /bin/usleep$SLEEPMSEC if[-f${oldbinpidfile}-a-f${pidfile}];then echo-n$"Gracefulshutdownofold$prog:" killproc-p${oldbinpidfile}${prog}-QUIT RETVAL=$? echo return fi done echo$"UpgradeFailed!" RETVAL=1 } configtest(){ if["$#"-ne0];then case"$1"in -q) FLAG=$1 ;; *) ;; esac shift fi ${Nginx}-t-c${conffile}$FLAG RETVAL=$? return$RETVAL } rh_status(){ status-p${pidfile}${Nginx} } #Seehowwewerecalled. case"$1"in start) rh_status>/dev/null2>&1&&exit0 start ;; stop) stop ;; status) rh_status RETVAL=$? ;; restart) configtest-q||exit$RETVAL stop start ;; upgrade) rh_status>/dev/null2>&1||exit0 upgrade ;; condrestart|try-restart) ifrh_status>/dev/null2>&1;then stop start fi ;; force-reload|reload) reload ;; configtest) configtest ;; *) echo$"Usage:$prog{start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}" RETVAL=2 esac exit$RETVAL
chmod+x/etc/init.d/Nginx
查看Nginx服务:
chkconfig--listNginx Nginx0:off1:off2:on3:on4:on5:on6:off