Nginx自动化安装脚本

小柒博客
小柒博客
小柒博客
313
文章
93
评论
2020-04-0716:26:33 评论 3.6K 2280字阅读7分36秒

此脚本是Nginx安装脚本,有需要朋友可以参考,脚本内容如下:

系统环境:CentOS 7.4

软件版本:1.16.1(最新稳定版)

[root@localhost ~]# vim auto_install_nginx.sh

#!/bin/bash
#2020-3-13 10:22:30
#By Author YangXingZhen
#Auto Install Nginx Soft

#Define Nginx path variables
NGINX_URL=http://nginx.org/download
NGINX_FILE=nginx-1.16.1.tar.gz
NGINX_FILE_DIR=nginx-1.16.1
NGINX_PREFIX=/usr/local/nginx
 
#Install Nginx Soft
if [ ! -d ${NGINX_PREFIX} ];then
	#Install Package
	yum -y install pcre pcre-devel openssl openssl-devel gcc gcc-c++ wget
	wget -c ${NGINX_URL}/${NGINX_FILE}
	tar zxf ${NGINX_FILE}
	cd ${NGINX_FILE_DIR}
	sed -i 's/1.16.1/ /;s/nginx\//nginx/' src/core/nginx.h
	useradd -s /sbin/nologin www
	./configure --prefix=${NGINX_PREFIX} \
	--user=www \
	--group=www \
	--with-http_ssl_module \
	--with-http_stub_status_module
	if [ $? -eq 0 ];then
		make && make install
		echo -e "\033[32mThe Nginx Install Success...\033[0m"
	else
		echo -e "\033[31mThe Nginx Install Failed...\033[0m"
		exit 1
	fi
else
	echo -e "\033[31mThe Nginx already Install...\033[0m"
	exit 1
fi

#Config Nginx
ln -sf ${NGINX_PREFIX}/sbin/nginx /usr/sbin
cat >${NGINX_PREFIX}/conf/nginx.conf <<EOF
	user www www;
	worker_processes auto;
	pid /usr/local/nginx/logs/nginx.pid;
events {
	use epoll;
	worker_connections 10240;
	multi_accept on;
	}
http	{
	include       mime.types;
	default_type  application/octet-stream;
	log_format  main  '\$remote_addr - \$remote_user [\$time_local] "\$request" '
                      '\$status \$body_bytes_sent "\$http_referer" '
                      '"\$http_user_agent" "\$http_x_forwarded_for"';
	access_log logs/access.log main;
	error_log logs/error.log warn;
	sendfile        on;
	tcp_nopush          on;
	keepalive_timeout  120;
	tcp_nodelay         on;
	server_tokens off;
	gzip    on;
	gzip_min_length 1k;
	gzip_buffers    4 64k;
	gzip_http_version 1.1;
	gzip_comp_level 4;
	gzip_types      text/plain application/x-javascript text/css application/xml;
	gzip_vary       on;
	client_max_body_size 10m;
	client_body_buffer_size 128k;
	proxy_connect_timeout 90;
	proxy_send_timeout 90;
	proxy_buffer_size 4k;
	proxy_buffers 4 32k;
	proxy_busy_buffers_size 64k;
	large_client_header_buffers 4 4k;
	client_header_buffer_size 4k;
	open_file_cache_valid 30s;
	open_file_cache_min_uses 1;
server {
	listen	80;
	server_name	localhost;
	location / {
	root	html;
	index index.html index.htm;
	}
  }
}
EOF

#Start Nginx
${NGINX_PREFIX}/sbin/nginx -t >/dev/null 2>&1
if [ $? -eq 0 ];then
	${NGINX_PREFIX}/sbin/nginx
fi

#Add power on self start
grep -qw "${NGINX_PREFIX}" /etc/rc.d/rc.local
if [ $? -ne 0 ];then
	echo "${NGINX_PREFIX}/sbin/nginx" >>/etc/rc.d/rc.local
	chmod +x /etc/rc.d/rc.local
fi

脚本执行方式:

[root@localhost ~]# sh auto_install_nginx.sh

继续阅读
  • 微信号
  • 微信扫一扫加我!
  • weinxin
  • 微信公众号
  • 微信扫一扫关注我!
  • weinxin
小柒博客
  • 本文由 发表于 2020-04-0716:26:33
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: