一键安装nginx脚本,并配置简单web界面

#!/bin/bash
# install nginx
#$1为nginx的版本,需要你在安装nginx的时候指定版本号,比如1.16.0或者1.14.2等
#$2为你的网站的域名比如www.9527edu.org跟你自己的实际的域名为准
#格式:./nginx.sh 1.16.0 www.9527edu.org
NG_VER="$1"
NG_VHOST="$2"
NG_BB="nginx-${NG_VER}.tar.gz"
NG_CS="--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  --user=nginx --group=nginx"
NG_ML="/usr/local/nginx"
NG_URL="http://nginx.org/download/"
if [ $# -eq 0 ];then
        echo "-------------"
        echo "Usage:{执行此命令需要加nginx版本如1.12.2或1.16.0后面加上你的网站的域名如www.9527edu.org具体格>式sh nginx.sh 1.16.1 www.9527edu.org}"
        exit
fi
if [ ! -d $NG_ML ];then
yum install wget make cmake gcc gcc-c++ tar pcre pcre-devel openssl openssl-devel -y
useradd -r -s /sbin/nologin nginx
wget -c $NG_URL$NG_BB
tar -xf nginx-${NG_VER}.tar.gz
cd nginx-$NG_VER
./configure --prefix=$NG_ML $NG_CS
make
make install
echo $?
echo /usr/local/nginx/sbin/nginx >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
mkdir -p /usr/local/nginx/conf.d/
mkdir -p /usr/local/nginx/html/$NG_VHOST
#nginx.conf
echo "
user  nginx;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  10240;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
  #gzip  on;
	include /usr/local/nginx/conf.d/*;
}
">/usr/local/nginx/conf/nginx.conf
echo "
server {
        listen       80;
        server_name  $NG_VHOST;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html/$NG_VHOST;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
	    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
		fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$NG_VHOST$fastcgi_script_name;
        include        fastcgi_params;
        }
}
">/usr/local/nginx/conf.d/${NG_VHOST}
echo "
<html>
<h1>$NG_VHOST NGINX test pages.</h1>
<hr color=red>
</html>
">/usr/local/nginx/html/${NG_VHOST}/index.html
$NG_ML/sbin/nginx
ss -ntl
fi


Powered By Z-BlogPHP 1.7.3

 Theme By 优美模版

本博客为开源博客,本博客联系QQ:372097243