#!/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 / {
        	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://php_pool;
			expires -1;
		}

        }

}
eof
echo "$nginx_rewrite" > $rewrite_dir/$domain.conf

cat > $conf_dir2/$domain.conf<<eof
<VirtualHost *:8080>
        ServerName   $domain
	$apache_alias
	$apache_alias2
        UseCanonicalName Off
        ServerAdmin  "admin@wondershare.com"
	DocumentRoot $web_dir/$domain/httpdocs
        DirectoryIndex index.html index.shtml index.php
	CustomLog "|/usr/local/apache2/bin/rotatelogs -l /data/www/logs/apache_log/access/${domain}_access.log.%Y-%m-%d 86400" combined
        ErrorLog "|/usr/local/apache2/bin/rotatelogs -l /data/www/logs/apache_log/error/${domain}_error.log.%Y-%m-%d 86400"
        <IfModule mod_ssl.c>
                SSLEngine off
        </IfModule>
        <Directory $web_dir/$domain/httpdocs/>
        <IfModule sapi_apache2.c>
                php_admin_flag engine on
                php_admin_flag safe_mode on
                php_admin_value open_basedir ".:$web_dir/$domain:/tmp"
        </IfModule>
        <IfModule mod_php5.c>
                php_admin_flag engine on
                php_admin_flag safe_mode on
                php_admin_value open_basedir ".:$web_dir/$domain:/tmp"
        </IfModule>
         Options -ExecCGI FollowSymLinks +Includes
         AllowOverride All
        </Directory>
ErrorDocument 404 /404.html
$apache_rewrite
</VirtualHost>
eof

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+apache)的更多相关文章

  1. add web server(nginx)

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

  2. delete web server(nginx+apache)

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

  3. NGINX Web Server Nginx web server

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

  4. Build Web Server with Apache and Passenger

    Follow the instructions at 2.6. Generic installation, upgrade and downgrade method: via tarball of P ...

  5. delete web server(nginx)

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

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

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

  7. 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 ...

  8. Web Server 与 App Server

    Web Server 常见的Web Server有Apache Server与Nginx. Apache Http Server是Apache软件基金会下的一个项目,是一款开源的HTTP服务器软件(它 ...

  9. Apache 后台服务器(主要处理php及一些功能请求 如:中文url)   Nginx 前端服务器(利用它占用系统资源少得优势来处理静态页面大量请求)   Lighttpd 图片服务器   总体来说,随着nginx功能得完善将使他成为今后web server得主流。

    Apache 后台服务器(主要处理php及一些功能请求 如:中文url) Nginx 前端服务器(利用它占用系统资源少得优势来处理静态页面大量请求) Lighttpd 图片服务器 总体来说,随着ngi ...

随机推荐

  1. spring boot 表单验证

    1 设置某个字段的取值范围 1.1 取值范围验证:@Min,@Max ① 实例类的属性添加注解@Min ② Controller中传入参数使用@Valid注解 1.2 不能为空验证:@NotNull ...

  2. 转 spring注解式参数校验

    转自: https://blog.csdn.net/jinzhencs/article/details/51682830 转自: https://blog.csdn.net/zalan01408980 ...

  3. 【XSY3156】简单计数II 容斥 DP

    题目大意 定义一个序列的权值为:把所有相邻的相同的数合并为一个集合后,所有集合的大小的乘积. 特别的,第一个数和最后一个数是相邻的. 现在你有 \(n\) 种数,第 \(i\) 种有 \(c_i\) ...

  4. XUGUO-书呆子-搜索书箱

    WorldCat 上的 米塔斯 通过图书馆馆藏的全球目录WorldCat,在附近的图书馆中查找所要的资料. < 用 Sketch 创作 Airiti Library華藝線上圖書館 BookBub ...

  5. MongoDB介绍与安装

    MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的.他支持的数据结构非常松散,是类似 json 的 bson 格式,因此可以存储比较复杂的数据 ...

  6. zookeeper在windows及linux(含多节点)环境下安装及其命令使用

    zookeeper下载 下载url:http://www.apache.org/dyn/closer.cgi/zookeeper/ windows下安装zookeeper 解压到D盘 创建logs目录 ...

  7. Python import hook

    转自http://blog.konghy.cn/2016/10/25/python-import-hook/,这里有好多好文章 import hook 通常被译为 探针.我们可以认为每当导入模块的时候 ...

  8. 网页三剑客之HTML

    Web服务本质 import socket def handle_request(client): request_data = client.recv(1024) print(request_dat ...

  9. Entity Framework入门教程(18)---EF6中基于代码进行配置方式

    EF6中基于代码进行配置方式 我们以前对EF进行配置时是在app.config/web.config下的<entityframework>节点下进行配置的,EF6引进了基于代码的配置方法. ...

  10. Contest1874 - noip基础知识五:动态规划(背包、树dp、记忆化、递推、区间、序列dp、dp优化)

    传送门 T1  dp[n][m]=dp[n-1][m-1]+dp[n-m][m] T2  ans=cat(n)*(n!)2  卡特兰数 T3  dp[i][j]=sigma(dp[i-1][j-a[i ...