nginx编译安装

来源:互联网 发布:智慧工地软件加盟 编辑:程序博客网 时间:2024/06/17 13:38
  1. nginx编译安装  
  2. ===========================================  
  3. Nginx官网:http://nginx.org/  
  4. Nginx官网下载地址(选择 Stable version 稳定版):http://nginx.org/en/download.html  
  5. 官网安装介绍:http://nginx.org/en/linux_packages.html  
  6.   
  7.   
  8. 一:安装  
  9.   
  10. 1.1:环境准备  
  11.     ~]# yum -y install gcc gcc-c++  pcre-devel  openssl-devel  
  12.   
  13. 2.2:编译安装  
  14.     ~]# tar -axf nginx-1.10.0.tar.gz  
  15.     ~]# cd nginx-1.10.0/  
  16.     ~]# useradd -r nginx  
  17.     ~]# ./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/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-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-file-aio --with-http_v2_module --with-ipv6  
  18.     ~}# make && make install  
  19.   
  20.   
  21. 1.3:加入环境变量  
  22.         ~]# vi /etc/profile.d/nginx.sh  
  23.         export PATH=$PATH:/usr/local/nginx/sbin/  
  24.   
  25.         ~]# source /etc/profile.d/nginx.sh  
  26.   
  27.   
  28. 1.4:启动与重启停止  
  29.         启动:nginx  
  30.         重载:nginx -s reload  
  31.         快速停止:nginx -s stop  
  32.         有序退出:nginx -s quit  
  33.   
  34.   
  35. 1.5:加入系统服务与开机启动  
  36.   
  37. CentOS 6   
  38.     ~]# vi /etc/rc.d/init.d/nginx  
  39.     ~]# chmod +x /etc/rc.d/init.d/nginx  
  40.   
  41. --------------------------file start---------------------------------  
  42. #!/bin/sh  
  43. #  
  44. # nginx - this script starts and stops the nginx daemon  
  45. #  
  46. # chkconfig:   - 85 15  
  47. # description:  Nginx is an HTTP(S) server, HTTP(S) reverse \  
  48. #               proxy and IMAP/POP3 proxy server  
  49. # processname: nginx  
  50.   
  51. # Source function library.  
  52. . /etc/rc.d/init.d/functions  
  53.   
  54. # Source networking configuration.  
  55. . /etc/sysconfig/network  
  56.   
  57. # Check that networking is up.  
  58. "$NETWORKING" = "no" ] && exit 0  
  59.   
  60. nginx="/usr/local/nginx/sbin/nginx"  
  61. prog=$(basename $nginx)  
  62.   
  63. sysconfig="/etc/sysconfig/$prog"  
  64. lockfile="/var/run/nginx.lock"  
  65. pidfile="/var/run/${prog}.pid"  
  66.   
  67. NGINX_CONF_FILE="/etc/nginx/nginx.conf"  
  68.   
  69. [ -f $sysconfig ] && . $sysconfig  
  70.   
  71. start() {  
  72.     [ -x $nginx ] || exit 5  
  73.     [ -f $NGINX_CONF_FILE ] || exit 6  
  74.     echo -n $"Starting $prog: "  
  75.     daemon $nginx -c $NGINX_CONF_FILE  
  76.     retval=$?  
  77.     echo  
  78.     [ $retval -eq 0 ] && touch $lockfile  
  79.     return $retval  
  80. }  
  81.   
  82. stop() {  
  83.     echo -n $"Stopping $prog: "  
  84.     killproc -p $pidfile $prog  
  85.     retval=$?  
  86.     echo  
  87.     [ $retval -eq 0 ] && rm -f $lockfile  
  88.     return $retval  
  89. }  
  90.   
  91. restart() {  
  92.     configtest_q || return 6  
  93.     stop  
  94.     start  
  95. }  
  96.   
  97. reload() {  
  98.     configtest_q || return 6  
  99.     echo -n $"Reloading $prog: "  
  100.     killproc -p $pidfile $prog -HUP  
  101.     echo  
  102. }  
  103.   
  104. configtest() {  
  105.     $nginx -t -c $NGINX_CONF_FILE  
  106. }  
  107.   
  108. configtest_q() {  
  109.     $nginx -t -q -c $NGINX_CONF_FILE  
  110. }  
  111.   
  112. rh_status() {  
  113.     status $prog  
  114. }  
  115.   
  116. rh_status_q() {  
  117.     rh_status >/dev/null 2>&1  
  118. }  
  119.   
  120. # Upgrade the binary with no downtime.  
  121. upgrade() {  
  122.     local oldbin_pidfile="${pidfile}.oldbin"  
  123.   
  124.     configtest_q || return 6  
  125.     echo -n $"Upgrading $prog: "  
  126.     killproc -p $pidfile $prog -USR2  
  127.     retval=$?  
  128.     sleep 1  
  129.     if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then  
  130.         killproc -p $oldbin_pidfile $prog -QUIT  
  131.         success $"$prog online upgrade"  
  132.         echo   
  133.         return 0  
  134.     else  
  135.         failure $"$prog online upgrade"  
  136.         echo  
  137.         return 1  
  138.     fi  
  139. }  
  140.   
  141. # Tell nginx to reopen logs  
  142. reopen_logs() {  
  143.     configtest_q || return 6  
  144.     echo -n $"Reopening $prog logs: "  
  145.     killproc -p $pidfile $prog -USR1  
  146.     retval=$?  
  147.     echo  
  148.     return $retval  
  149. }  
  150.   
  151. case "$1" in  
  152.     start)  
  153.         rh_status_q && exit 0  
  154.         $1  
  155.         ;;  
  156.     stop)  
  157.         rh_status_q || exit 0  
  158.         $1  
  159.         ;;  
  160.     restart|configtest|reopen_logs)  
  161.         $1  
  162.         ;;  
  163.     force-reload|upgrade)   
  164.         rh_status_q || exit 7  
  165.         upgrade  
  166.         ;;  
  167.     reload)  
  168.         rh_status_q || exit 7  
  169.         $1  
  170.         ;;  
  171.     status|status_q)  
  172.         rh_$1  
  173.         ;;  
  174.     condrestart|try-restart)  
  175.         rh_status_q || exit 7  
  176.         restart  
  177.         ;;  
  178.     *)  
  179.         echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"  
  180.         exit 2  
  181. esac  
  182. --------------------------file end---------------------------------  
  183.     开机启动  
  184.         ~]# chkconfig --add nginx  
  185.         ~]# chkconfig --level 345 nginx on  
  186.         ~]# chkconfig --list nginx  
  187.             nginx           0:off   1:off   2:off   3:on    4:on    5:on    6:off  
  188.   
  189.     开机不启动  
  190.         ~]# chkconfig nginx off  
  191.         ~]# chkconfig --list nginx  
  192.             nginx           0:off   1:off   2:off   3:off   4:off   5:off   6:off  
  193.   
  194.   
  195.   
  196.   
  197. CentOS 7:  
  198.     ~]# vi /usr/lib/systemd/system/nginx.service  
  199. --------------------------file start---------------------------------  
  200. [Unit]    
  201. Description=nginx    
  202. After=network.target remote-fs.target nss-lookup.target  
  203.   
  204. [Service]    
  205. Type=forking  
  206. ExecStart=/usr/local/nginx/sbin/nginx    
  207. ExecReload=/usr/local/nginx/sbin/nginx -s reload  
  208. ExecStop=/usr/local/nginx/sbin/nginx -s  stop  
  209. PrivateTmp=true    
  210.   
  211. [Install]    
  212. WantedBy=multi-user.target  
  213. --------------------------file end---------------------------------  
  214.   
  215.     开机启动  
  216.         ~]# systemctl enable nginx.service  
  217.     开机不启动  
  218.         ~]# systemctl disable nginx.service  
  219.     其他操作:  
  220.         ~]# systemcl ( status | start | stop | reload | restart ) nginx.service  
  221.   
  222.   
  223.     其他操作:  
  224.         ~]# service nginx (start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs)  
1 0
原创粉丝点击