#!/bin/bash
#
# Web Server Install Script
# Last Updated 2012.09.24
#
##### modify by WanJie 2012.09.24 #####

conf_dir1="/usr/local/nginx/conf/vhost.d"
#conf_dir2="/usr/local/apache2/conf/vhost.d"
rewrite_dir='/usr/local/nginx/conf/rewrite.d'
web_dir="/data/www/vhosts"

function dis_info {
        clear
        echo
        echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
        echo "Add Virtual Host"
        echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
        echo
}

if [ $# -eq 0 ];then
	dis_info;
	echo "Pleast input domain:"
	read -p "(Default or Example domain: www.example.com):" domain ;
fi

if [ $# -eq 1 ];then
	domain=$1
fi
#else
#	echo "parameter is error."
#	exit 1
#fi

if [[ $domain == "" ]];then
        domain="example.com"
else if [[ $domain =~ ^www\.(.*)$ ]];then
	nonwww_domain=${domain#www.}
	domain=$nonwww_domain
	wwwdomain=www.$nonwww_domain
	oriwwwdomain=ori-$wwwdomain
fi

fi

echo
echo "domain:$domain"
echo "-----------------------------------------"
echo

if [[ -f "$conf_dir1/$domain.conf" ]];then
        echo "$conf_dir1/$domain.conf is exists!"
        exit
fi

#if [[ -f "$conf_dir2/$domain.conf" ]];then
#        echo "$conf_dir2/$domain.conf is exists!"
#        exit
#fi

if [[ -f "$rewrite_dir/$domain.conf" ]];then
	echo "$rewrite_dir/$domain.conf is exists!"
	exit
fi

#echo "Do you want to add ftp Account? (y/n)"
#read ftp_account
#if [[ $ftp_account == "y" || $ftp_account == "Y" ]];then
#       read -p "ftp user name:" ftp_user
#       read -p "ftp user password:" ftp_pass
#       echo "Create FTP virtual host directory."
#       mkdir -p $web_dir/$domain/httpdocs
#       useradd -d $web_dir/$domain/httpdocs/ -s /sbin/nologin $ftp_user -g users
#       echo "$ftp_pass" | passwd --stdin $ftp_user
#       chown -R apache:users $web_dir/$domain/httpdocs
#	chmod 775 apache:users $web_dir/$domain/httpdocs
#       chown apache:apache $web_dir/$domain
#       chmod 755 $web_dir/$domain
#       echo
#fi

mkdir -p $web_dir/$domain/httpdocs
if [[ ! -d $conf_dir1 ]];then
	mkdir -p $conf_dir1
fi
#if [[ ! -d $conf_dir1 ]];then
#	mkdir -p $conf_dir2
#fi
if [[ ! -d $rewrite_dir ]];then
	mkdir -p $rewrite_dir
fi

chown -R apache.users $web_dir/$domain
chown -R apache:users $web_dir/$domain/httpdocs

if [[ $nonwww_domain != "" ]];then
	apache_alias="ServerAlias $wwwdomain"
	apache_alias2="ServerAlias $oriwwwdomain"
	apache_rewrite="RewriteEngine On
RewriteCond %{HTTP_HOST} ^$nonwww_domain [NC]
RewriteRule ^/(.*)$     http://$wwwdomain/\$1 [R=301,L]"
	nginx_alias="$wwwdomain $oriwwwdomain"
	nginx_rewrite="if (\$host ~* ^$nonwww_domain){ rewrite ^(.*)$ http://$wwwdomain\$1 permanent;}
	if (\$request_uri ~ ^/(.*)/(index|indice).(html)) { rewrite ^/(.*)/(index|indice).(html) /\$1   permanent;}"
else
	apache_alias=""
	apache_rewrite=""
	nginx_alias=""
	nginx_rewrite="if (\$request_uri ~ ^/(.*)/(index|indice).(html)) { rewrite ^/(.*)/(index|indice).(html) /\$1   permanent;}"
fi

echo "Create domain conf."

cat > $conf_dir1/$domain.conf<<eof
server {
        listen 80;
        server_name     $domain $wwwdomain $oriwwwdomain;
        access_log      /data/www/logs/nginx_log/access/${domain}_access.log main ;
        error_log       /data/www/logs/nginx_log/error/${domain}_error.log ;
        root            /data/www/vhosts/$domain/httpdocs ;
        index           index.html index.shtml index.php ;
	include		rewrite.d/${domain}.conf ;
	error_page  404 403             /404.html;	

 #       location ~ \.php$ {
 #                       proxy_pass http://php_pool;
 #                       include proxy_params;
 #			expires -1;
 #        }
	location ~ \.php$ {
        	fastcgi_pass 127.0.0.1:9000;
        	fastcgi_index index.php;
        	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        	include fastcgi_params;
        	expires -1;
        }

        location / {
        	include proxy_params;
		if (!-d \$request_filename){
			set \$flag 1\$flag;
		}
		if (!-f \$request_filename){
			set \$flag 2\$flag;
		}
		if (\$flag = "21"){
        	        proxy_pass http://127.0.0.1:9000;
			expires -1;
		}

        }

}
eof
echo "$nginx_rewrite" > $rewrite_dir/$domain.conf
echo
echo "web site infomations:"
echo "========================================"
echo "domain list:$domain "
echo "----------------------------------------"
echo "website dir:$web_dir/$domain"
echo "----------------------------------------"
echo "nginx_conf file:$conf_dir1/$domain.conf"
echo "----------------------------------------"
#echo "apache2_conf file:$conf_dir2/$domain.conf"
echo "----------------------------------------"

#if [[ $ftp_account == "y" || $access_log == "Y" ]];then
#        echo "ftp user:$ftp_user password:$ftp_pass";
#        echo "----------------------------------------"
#fi
echo "web site is OK"
echo "========================================"

  

使用方法:

  执行脚本,并传入网站域名作为参数(网站域名不能以www开头)

add web server(nginx)的更多相关文章

  1. add web server(nginx+apache)

    #!/bin/bash # # Web Server Install Script # Last Updated 2012.09.24 # ##### modify by WanJie 2012.09 ...

  2. NGINX Web Server Nginx web server

    原文地址:http://nginx.com/resources/admin-guide/web-server/ NGINX Web Server Nginx web server This secti ...

  3. delete web server(nginx+apache)

    #!/bin/bash conf_dir1="/usr/local/nginx/conf/vhost.d" conf_dir2="/usr/local/apache2/c ...

  4. delete web server(nginx)

    #!/bin/bash conf_dir1="/usr/local/nginx/conf/vhost.d" #conf_dir2="/usr/local/apache2/ ...

  5. Nginx负载均衡:分布式/热备Web Server的搭建

    Nginx是一款轻量级的Web server/反向代理server及电子邮件(IMAP/POP3)代理server.并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开 ...

  6. Install the high performance Nginx web server on Ubuntu

    Look out Apache, there's a web server – Nginx (pronounced Engine X) – that means to dismantle you as ...

  7. Setting up Django and your web server with uWSGI and nginx

    https://uwsgi.readthedocs.io/en/latest/tutorials/Django_and_nginx.html Setting up Django and your we ...

  8. [r]Setting up Django and your web server with uWSGI and nginx

    Setting up Django and your web server with uWSGI and nginx This tutorial is aimed at the Django user ...

  9. virtualbox搭建ubuntu server nginx+mysql+tomcat web服务器1 (未完待续)

    virtualbox搭建ubuntu server nginx+mysql+tomcat web服务器1 (未完待续) 第一次接触到 linux,不知道linux的确很强大,然后用virtualbox ...

随机推荐

  1. MongoDB 学习手册 - CURD

    mongoDB 增加数据 // mongoDB 增加数据: //新增数据insert( 字典 ) 表示插入一条数据,insert([字典]) 表示插入多条数据 // db.text01.insert( ...

  2. zookeeper的ACL权限控制

    ACL:Access Control List  访问控制列表 1.  简介 0.概述 ACL 权限控制,使用:scheme:id:perm 来标识,主要涵盖 3 个方面: 权限模式(Scheme): ...

  3. Eclipse打印GC日志

    一.生成gc.log 第一步:右键项目或文件——Run As——Run Configurations. 第二步:点击Arguments,在VM arguments中填写-Xloggc:F:/gc.lo ...

  4. (转)如何用TensorLayer做目标检测的数据增强

    数据增强在机器学习中的作用不言而喻.和图片分类的数据增强不同,训练目标检测模型的数据增强在对图像做处理时,还需要对图片中每个目标的坐标做相应的处理.此外,位移.裁剪等操作还有可能使得一些目标在处理后只 ...

  5. Serv-U日志文件保存设置【转】

    Serv-U的日志默认是不保存在本地的,但是大多数企业对于文件传输是有审计需求的,所以这里我们可以手动配置Serv-U的日志保存到本地文件. 首先打开“域活动”,选择“设置”,在“记录到文件”处设置日 ...

  6. HTTP协议06-报文首部

    HTTP报文格式 ​ HTTP协议的请求和响应报文中必定包含HTTP首部.首部内容为客户端和服务器分别处理请求和响应提供所需要的信息. 1)HTTP请求报文 在请求中,HTTP报文由方法.URI.HT ...

  7. 在Visual Studio中使用C++创建和使用DLL

    [什么是DLL(动态链接库)?] DLL是一个包含可由多个程序同时使用的代码和数据的库.例如:在Windows操作系统中,Comdlg32 DLL执行与对话框有关的常见函数.因此,每个程序都可以使用该 ...

  8. VS2013中编译openssl的步骤和使用设置

    一.VS2013中编译openssl的步骤 版本号:openssl-1.0.1e 1.下载 OpenSSL http://www.openssl.org/,并解压到d:\openssl-1.0.1e目 ...

  9. Kafka中文官方文档

    参见链接:http://orchome.com/kafka/index

  10. Laravel 5.2问题-----postman进api的post请求,为什么出现Forbidden?

    Forbidden?就纳闷了,有写验证规则的,但是它出现紧张,感觉就是我落了设置什么东西了才会这样? 果不其然, Laravel有个一自动验证的,创建的时候是默认打开的, namespace App\ ...