CentOS 6.5 源码安装Nginx

前端之家收集整理的这篇文章主要介绍了CentOS 6.5 源码安装Nginx前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、软件配置信息

CentOS 6.5

二、必要软件准备

检查安装pcre,openssl,gzip命令如下:

  1. yuminstall-yzlibzlib-develpcrepcre-developensslopenssl-devel

三、创建Nginx用户与组

  1. [root@localhostsrc]#groupaddNginx
  2. [root@localhostsrc]#useradd-r-gNginx-s/sbin/nologin-MNginx

四、下载解压

Nginx可以从官网下载:http://Nginx.org/

也可以通过命令直接下载,我的当前目录是/usr/local/src:

  1. [root@localhostsrc]#wgethttp://Nginx.org/download/Nginx-1.10.1.tar.gz

解压:

  1. [root@localhostsrc]#tarzxvfNginx-1.10.1.tar.gz
  2. [root@localhostsrc]#cdNginx-1.10.1

五、开始安装

  1. [root@localhostsrc]#cdNginx-1.6.3
  2.  
  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
  4.  
  5. ./configure\
  6. --prefix=/usr/local/Nginx\
  7. --sbin-path=/usr/sbin/Nginx\
  8. --conf-path=/usr/local/Nginx/conf/Nginx.conf\
  9. --error-log-path=/var/log/Nginx/error.log\
  10. --http-log-path=/var/log/Nginx/access.log\
  11. --pid-path=/var/run/Nginx.pid\
  12. --lock-path=/var/run/Nginx.lock\
  13. --http-client-body-temp-path=/var/cache/Nginx/client_temp\
  14. --http-proxy-temp-path=/var/cache/Nginx/proxy_temp\
  15. --http-fastcgi-temp-path=/var/cache/Nginx/fastcgi_temp\
  16. --http-uwsgi-temp-path=/var/cache/Nginx/uwsgi_temp\
  17. --http-scgi-temp-path=/var/cache/Nginx/scgi_temp\
  18. --user=Nginx\
  19. --group=Nginx\
  20. --with-http_ssl_module\
  21. --with-http_realip_module\
  22. --with-http_addition_module\
  23. --with-http_sub_module\
  24. --with-http_dav_module\
  25. --with-http_flv_module\
  26. --with-http_mp4_module\
  27. --with-http_gunzip_module\
  28. --with-http_gzip_static_module\
  29. --with-http_random_index_module\
  30. --with-http_secure_link_module\
  31. --with-http_stub_status_module\
  32. --with-http_auth_request_module\
  33. --with-file-aio\
  34. --with-http_spdy_module\
  35. --with-ipv6\
  36. --with-pcre
  37.  
  38. [root@localhostNginx-1.6.3]#make
  39. [root@localhostNginx-1.6.3]#makeinstall

六、启动停止

启动命令:

  1. [root@localhostNginx-1.6.3]#/usr/sbin/Nginx

测试,直接用curl命令读取web信息:

  1. [root@localhostsbin]#curl-shttp://localhost|grepNginx.com

关闭命令:

  1. [root@localhostNginx-1.6.3]#/usr/sbin/Nginx-sstop
  2. reload,当你修改配置时,用此命令不用再重启就生效了:
  3. [root@localhostNginx-1.6.3]#/usr/sbin/Nginx-sreload

七、配置Nginx为系统服务
添加如下文件

  1. vi/etc/init.d/Nginx
  2. #!/bin/sh
  3. #
  4. #NginxStartupscriptforNginx
  5. #
  6. #chkconfig:-8515
  7. #processname:Nginx
  8. #config:/etc/Nginx/Nginx.conf
  9. #config:/etc/sysconfig/Nginx
  10. #pidfile:/var/run/Nginx.pid
  11. #description:NginxisanHTTPandreverseproxyserver
  12. #
  13. ###BEGININITINFO
  14. #Provides:Nginx
  15. #required-Start:$local_fs$remote_fs$network
  16. #required-Stop:$local_fs$remote_fs$network
  17. #Default-Start:2345
  18. #Default-Stop:016
  19. #Short-Description:startandstopNginx
  20. ###ENDINITINFO
  21.  
  22. #Sourcefunctionlibrary.
  23. ./etc/rc.d/init.d/functions
  24.  
  25. if[-L$0];then
  26. initscript=`/bin/readlink-f$0`
  27. else
  28. initscript=$0
  29. fi
  30.  
  31. sysconfig=`/bin/basename$initscript`
  32.  
  33. if[-f/etc/sysconfig/$sysconfig];then
  34. ./etc/sysconfig/$sysconfig
  35. fi
  36.  
  37. Nginx=${Nginx-/usr/sbin/Nginx}
  38. prog=`/bin/basename$Nginx`
  39. conffile=${CONFFILE-/etc/Nginx/Nginx.conf}
  40. lockfile=${LOCKFILE-/var/lock/subsys/Nginx}
  41. pidfile=${PIDFILE-/var/run/Nginx.pid}
  42. SLEEPMSEC=${SLEEPMSEC-200000}
  43. UPGRADEWAITLOOPS=${UPGRADEWAITLOOPS-5}
  44. RETVAL=0
  45.  
  46. start(){
  47. echo-n$"Starting$prog:"
  48.  
  49. daemon--pidfile=${pidfile}${Nginx}-c${conffile}
  50. RETVAL=$?
  51. echo
  52. [$RETVAL=0]&&touch${lockfile}
  53. return$RETVAL
  54. }
  55.  
  56. stop(){
  57. echo-n$"Stopping$prog:"
  58. killproc-p${pidfile}${prog}
  59. RETVAL=$?
  60. echo
  61. [$RETVAL=0]&&rm-f${lockfile}${pidfile}
  62. }
  63.  
  64. reload(){
  65. echo-n$"Reloading$prog:"
  66. killproc-p${pidfile}${prog}-HUP
  67. RETVAL=$?
  68. echo
  69. }
  70.  
  71. upgrade(){
  72. oldbinpidfile=${pidfile}.oldbin
  73.  
  74. configtest-q||return
  75. echo-n$"Startingnewmaster$prog:"
  76. killproc-p${pidfile}${prog}-USR2
  77. echo
  78.  
  79. foriin`/usr/bin/seq$UPGRADEWAITLOOPS`;do
  80. /bin/usleep$SLEEPMSEC
  81. if[-f${oldbinpidfile}-a-f${pidfile}];then
  82. echo-n$"Gracefulshutdownofold$prog:"
  83. killproc-p${oldbinpidfile}${prog}-QUIT
  84. RETVAL=$?
  85. echo
  86. return
  87. fi
  88. done
  89.  
  90. echo$"UpgradeFailed!"
  91. RETVAL=1
  92. }
  93.  
  94. configtest(){
  95. if["$#"-ne0];then
  96. case"$1"in
  97. -q)
  98. FLAG=$1
  99. ;;
  100. *)
  101. ;;
  102. esac
  103. shift
  104. fi
  105. ${Nginx}-t-c${conffile}$FLAG
  106. RETVAL=$?
  107. return$RETVAL
  108. }
  109.  
  110. rh_status(){
  111. status-p${pidfile}${Nginx}
  112. }
  113.  
  114. #Seehowwewerecalled.
  115. case"$1"in
  116. start)
  117. rh_status>/dev/null2>&1&&exit0
  118. start
  119. ;;
  120. stop)
  121. stop
  122. ;;
  123. status)
  124. rh_status
  125. RETVAL=$?
  126. ;;
  127. restart)
  128. configtest-q||exit$RETVAL
  129. stop
  130. start
  131. ;;
  132. upgrade)
  133. rh_status>/dev/null2>&1||exit0
  134. upgrade
  135. ;;
  136.  
  137. condrestart|try-restart)
  138. ifrh_status>/dev/null2>&1;then
  139. stop
  140. start
  141. fi
  142. ;;
  143. force-reload|reload)
  144. reload
  145. ;;
  146. configtest)
  147. configtest
  148. ;;
  149. *)
  150. echo$"Usage:$prog{start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}"
  151. RETVAL=2
  152. esac
  153.  
  154. exit$RETVAL
  1. 修改文件权限:

  1. chmod+x/etc/init.d/Nginx

查看Nginx服务:

  1. chkconfig--listNginx
  2. Nginx0:off1:off2:on3:on4:on5:on6:off

猜你在找的CentOS相关文章