Shell 配置Nginx虚拟主机脚本
#!/bin/bash
nginx_src="/usr/src"
nginx_dir="/usr/local/nginx"
nginx_url="http://nginx.org/download"
nginx_ver="1.16.0"
nginx_soft="nginx-${nginx_ver}.tar.gz"
nginx_args="--prefix=${nginx_dir} --user=nginx --group=nginx --with-http_stub_status_module"
yum install gcc pcre pcre-devel zlib zlib-devel wget make openssl-devel net-tools -y
sed -i 's/enforcing/disabled/g' /etc/selinux/config
systemctl stop firewalld.service
cd $nginx_src
wget -c $nginx_url/$nginx_soft
tar xf $nginx_soft
cd nginx-${nginx_ver}
useradd -s /sbin/nologin nginx
./configure $nginx_args
make&&make install
$nginx_dir/sbin/nginx
ps -ef | grep nginx | grep -v grep
echo -e "\033[32m-----------------config Nginx vhost now------------------------------\033[0m"
#config Nginx vhost
cd $nginx_dir/conf
\cp nginx.conf nginx.conf.bak
\cp $nginx_src/nginx-${nginx_ver}/conf/nginx.conf $nginx_dir/conf
sed -i -e '/#/d' -e '/^$/d' -e '/server/,$d' nginx.conf
echo -e "include /usr/local/nginx/conf/vhosts/*.conf; \n}" >>nginx.conf
mkdir -p vhosts
cd vhosts
cat >v1.test.conf<<EOF
server {
listen 80;
server_name v1.test.net;
location / {
root html/v1.test.net;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
EOF
mkdir -p $nginx_dir/html/v1.test.net
cat >$nginx_dir/html/v1.test.net/index.html<<EOF
<html>
<h1>v1.www.net Test Pages.</h1>
<hr color=red>
</html>
EOF
$nginx_dir/sbin/nginx -t
$nginx_dir/sbin/nginx -s reload
curl 127.0.0.1
目录 返回
首页