Shell Script Installation Nginx

Source: Internet
Author: User

#!/bin/Bashn_url="http://nginx.org/download/nginx-1.8.0.tar.gz"N_pack=`Echo$N _url|awk-F'/' '{print $}'' N_upack=`Echo$N _url|awk-F'/' '{print $}'|awk-F'.' '{print $ "." $ "." $-$}'' N_dir="/usr/local/nginx"functionNginx () {if[ `WhoAmI` !="Root"]; Then        Echo "Installtion This package needs root user."exit1fi    Yum-YInstallOpenssl-devel Pcre-devel zlib-Devel [! $? -eq0] &&Exitwget-c $N _url [! $? -eq0] &&ExitTarzxf $N _pack cd $N _upack useradd-m-s/sbin/nologin www./configure--prefix= $N _dir--user=www--group=www--with-http_stub_status_module--with-Http_ssl_module [! $? -eq0] &&Exit Make-j 'grepProcessor/proc/cpuinfo |WC-L ' && Make Install    mkdir$N _dir/conf/Vhostmkdir/data/www-P}functionconfig () {Cat> $N _dir/conf/nginx.conf <<'EOF'user www www;worker_processes auto;error_log/usr/local/nginx/logs/Error.log crit;pid/usr/local/nginx/Nginx.pid;worker_rlimit_nofile102400; events {use epoll;  Multi_accept on; Worker_connections102400;}  HTTP {include mime.types; Default_type Application/octet-stream; CharSet UTF-8;   Server_tokens off;  Sendfile on;  Tcp_nopush on;  Tcp_nodelay on; Keepalive_timeout -; Client_header_timeoutTen; Client_body_timeoutTen;  Client_header_buffer_size 4k; Server_names_hash_bucket_size -; Large_client_header_buffers432k;  Client_max_body_size 100m; Send_timeoutTen;  Reset_timedout_connection on; Open_file_cache Max=102400Inactive=20s; Open_file_cache_min_uses1;    Open_file_cache_valid 30s; Fastcgi_connect_timeout -; Fastcgi_send_timeout -; Fastcgi_read_timeout -;  Fastcgi_buffer_size 64k; Fastcgi_buffers464k;  Fastcgi_busy_buffers_size 128k;    Fastcgi_temp_file_write_size 128k; gzipOn ;  Gzip_min_length 1k; Gzip_buffers416k; Gzip_http_version1.1;  Gzip_vary on; Gzip_comp_level2; Gzip_disable"MSIE [1-6]\.";   Gzip_proxied any; Gzip_types text/plain Application/x-javascript text/css application/XML; Log_format Access'$remote _addr-$remote _user [$time _local] "$request"'              '$status $body _bytes_sent "$http _referer"'              '"$http _user_agent" $http _x_forwarded_for'; Access_log/usr/local/nginx/logs/Access.log access; Include Vhost/*. conf;}    Eofcat > $N _dir/conf/vhost/test.conf << eofserver {Listen 80;    server_name localhost;    Index index.html index.htm index.php;    root/data/www;        Location/status {stub_status on;    Access_log off; }}eofcat >/data/www/index.html << eof"]; ThenUseradd-m-s/bin/Nologin $userfiOptions= ' $nginx-V2>&1|grep "Configure arguments:"`    forOptinch$options; Do       if[ `Echo$opt |grep ". *-temp-path"` ]; Thenvalue=`Echo$opt |Cut-D"="-F2`           if[!-D"$value"]; Then               # Echo "Creating"$valuemkdir-P $value &&Chown-R $user $valuefi       fi    Done} start () {[-X $nginx] | | Exit5    [ -F $NGINX _conf_file] | | Exit6Make_dirsEcho-N $"starting $prog:"Daemon $nginx-c $NGINX _conf_file retval=$?Echo[$retval-eq0] &&Touch$Lockfilereturn $retval} stop () {Echo-N $"stopping $prog:"Killproc $prog-QUIT retval=$?Echo[$retval-eq0] &&RM-F $Lockfilereturn $retval} restart () {configtest|| Return $?StopSleep 1start} 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 " $" inchstart) 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: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"Exit2        ;;EsacEOFchmod 755/etc/init.d/Nginxchkconfig--add Nginxchkconfig nginx onEcho-E"\033[37m ========= nginx Install success =========="Echo-E"\033[37m ========= Please reboot system =========="}nginx config

Shell Script Installation Nginx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.