T-hua 发表于 2017-1-3 11:36:15

Centos6.8 Nginx一键安装脚本

#!/bin/bash
softpath=/usr/local/src
nginxver="nginx-1.8.0"
nginxpath=/usr/local/nginx
function install_nginx {
clear
yum install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* -y
useradd -M -u 8001 -s /sbin/nologinnginx
tar xf pcre-8.37.tar.bz2 -C $softpath
tar xvf ${nginxver}.tar.gz -C $softpath
cd $softpath/$nginxver
./configure --prefix=$nginxpath --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module--with-http_flv_module --with-http_mp4_module --with-pcre=$softpath/pcre-8.37
make && make install
mkdir -p /date/www
mkdir -p /date/wwwlogs
cat >$nginxpath/conf/nginx.conf<<EOF
usernginx nginx;

worker_processes auto;

error_log/date/wwwlogs/nginx_error.logcrit;

pid      /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
    {
      use epoll;
      worker_connections 51200;
      multi_accept on;
    }

http
    {
      include       mime.types;
      default_typeapplication/octet-stream;

      server_names_hash_bucket_size 128;
      client_header_buffer_size 32k;
      large_client_header_buffers 4 32k;
      client_max_body_size 50m;

    #include blocksip.conf; #denyip
      sendfile   on;
      tcp_nopush on;

      keepalive_timeout 60;

      tcp_nodelay on;

      fastcgi_connect_timeout 300;
      fastcgi_send_timeout 300;
      fastcgi_read_timeout 300;
      fastcgi_buffer_size 64k;
      fastcgi_buffers 4 64k;
      fastcgi_busy_buffers_size 128k;
      fastcgi_temp_file_write_size 256k;

      gzip on;
      gzip_min_length1k;
      gzip_buffers   4 16k;
      gzip_http_version 1.1;
      gzip_comp_level 2;
      gzip_types   text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
      gzip_vary on;
      gzip_proxied   expired no-cache no-store private auth;
      gzip_disable   "MSIE \.";

      #limit_conn_zone $binary_remote_addr zone=perip:10m;
      ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

      server_tokens off;
      access_log off;

server
    {
      listen 80 default_server;
      #listen [::]:80 default_server ipv6only=on;
      server_name www.xiaohua.cn;
      index index.html index.htm index.php;
      root/date/www;

      #error_page   404   /404.html;
      #include enable-php.conf;

      location /nginx_status
      {
            stub_status on;
            access_log   off;
      }

      location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
      {
            expires      30d;
      }

      location ~ .*\.(js|css)?$
      {
            expires      12h;
      }

      location ~ /\.
      {
            deny all;
      }

      access_logoff;
    }
#include vhost/*.conf;
}
EOF

cat >/etc/init.d/nginx<<EOF
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
      echo -n $"Starting \$prog: "
      mkdir -p /dev/shm/nginx_temp
      daemon \$NGINX_SBIN -c \$NGINX_CONF
      RETVAL=\$?
      echo
      return \$RETVAL
}
stop() {
      echo -n $"Stopping \$prog: "
      killproc -p \$NGINX_PID \$NGINX_SBIN -TERM
      rm -rf /dev/shm/nginx_temp
      RETVAL=\$?
      echo
      return \$RETVAL
}
reload(){
      echo -n $"Reloading \$prog: "
      killproc -p \$NGINX_PID \$NGINX_SBIN -HUP
      RETVAL=\$?
      echo
      return \$RETVAL
}
restart(){
      stop
      start
}
configtest(){
    \$NGINX_SBIN -c \$NGINX_CONF -t
    return 0
}
case "\$1" in
start)
      start
      ;;
stop)
      stop
      ;;
reload)
      reload
      ;;
restart)
      restart
      ;;
configtest)
      configtest
      ;;
*)
      echo $"Usage: $0 {start|stop|reload|restart|configtest}"
      RETVAL=1
esac
exit \$RETVAL
EOF
chmod +x /etc/init.d/nginx
/etc/init.d/nginx restart
chkconfig nginx on
}
install_nginx
注:有问题请访问nginx专题介绍

页: [1]
查看完整版本: Centos6.8 Nginx一键安装脚本