#!/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. 阿里云对象存储OSS与文件存储NAS的区别

    一.简介 应用场景:选择一款存储产品,面向文档数据的存取,不会涉及到数据处理. 产品选型主要从OSS和NAS中选择一款,满足文档存储的需求. 二.NAS优缺点 NAS 是一种采用直接与网络介质相连的特 ...

  2. Android——图片轮播

    Android技术——轮播功能 轮播需要什么? 答:实现图片与广告语展示.循环播发以及手动切换.支持加载本地与网络图片. 性能优化? 答:多张图片与指示器展示.自动与定时.循环播发.滑动流畅并且无卡顿 ...

  3. Shell命令-文件及目录操作之touch、tree

    文件及目录操作 - touch.tree 1.touch:创建文件或更改文件时间戳 touch命令的功能说明 touch命令用于创建新的空文件或改变已有文件的时间戳属性. touch命令的语法格式 t ...

  4. Kickstart 和 Cobbler ks.cfg文件详解

    ks.cfg文件组成大致分为3段 命令段 键盘类型,语言,安装方式等系统的配置,有必选项和可选项,如果缺少某项必选项,安装时会中断并提示用户选择此项的选项 软件包段 %packages @groupn ...

  5. 解决SVN一直弹出登录问题,eclipse.tmatesoft.com

    Windows->preferences->Igonored Resources Add Pattern.. .project .classpath .settings 添加这三个: 把C ...

  6. 深入理解AMQP协议

    深入理解AMQP协议 2018年10月22日 12:32:16 一剑何风情 阅读数:1941   文章目录 一.AMQP 是什么 二.AMQP模型 工作过程 深入理解 三.Exchange交换机 默认 ...

  7. Codeforces Beta Round #51 D. Beautiful numbers(数位dp)

    题目链接:https://codeforces.com/contest/55/problem/D 题目大意:给你一段区间[l,r],要求这段区间中可以整除自己每一位(除0意外)上的数字的整数个数,例如 ...

  8. elk每日清除30天索引脚本

      日常elk产生日志太多,故写个脚本放在定时任务,定时清理脚本 查询索引: curl -XGET 'http://127.0.0.1:9200/_cat/indices/?v'   删除索引: cu ...

  9. 使用catboost解决ML中高维度不平衡数据集挑战的解决方案

    python风控评分卡建模和风控常识(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005214003&am ...

  10. velocity 新手用小常识--开源,简单易上手

    项目中经常用到的 .vm 后缀文件是什么? 基于 java 的 velocity 模版引擎的一种页面控制文件,是一些类似 html 语句和一种叫 VLT 的语句构成   velocity --美 [v ...