add web server(nginx+apache)
#!/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)的更多相关文章
- add web server(nginx)
#!/bin/bash # # Web Server Install Script # Last Updated 2012.09.24 # ##### modify by WanJie 2012.09 ...
- delete web server(nginx+apache)
#!/bin/bash conf_dir1="/usr/local/nginx/conf/vhost.d" conf_dir2="/usr/local/apache2/c ...
- NGINX Web Server Nginx web server
原文地址:http://nginx.com/resources/admin-guide/web-server/ NGINX Web Server Nginx web server This secti ...
- Build Web Server with Apache and Passenger
Follow the instructions at 2.6. Generic installation, upgrade and downgrade method: via tarball of P ...
- delete web server(nginx)
#!/bin/bash conf_dir1="/usr/local/nginx/conf/vhost.d" #conf_dir2="/usr/local/apache2/ ...
- Nginx负载均衡:分布式/热备Web Server的搭建
Nginx是一款轻量级的Web server/反向代理server及电子邮件(IMAP/POP3)代理server.并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开 ...
- 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 ...
- Web Server 与 App Server
Web Server 常见的Web Server有Apache Server与Nginx. Apache Http Server是Apache软件基金会下的一个项目,是一款开源的HTTP服务器软件(它 ...
- Apache 后台服务器(主要处理php及一些功能请求 如:中文url) Nginx 前端服务器(利用它占用系统资源少得优势来处理静态页面大量请求) Lighttpd 图片服务器 总体来说,随着nginx功能得完善将使他成为今后web server得主流。
Apache 后台服务器(主要处理php及一些功能请求 如:中文url) Nginx 前端服务器(利用它占用系统资源少得优势来处理静态页面大量请求) Lighttpd 图片服务器 总体来说,随着ngi ...
随机推荐
- 如何给框架添加API接口日志
前言 用的公司的框架,是MVC框架,看了下里面的日志基类,是操作日志,对增删改进行记录, 夸张的是一张业务的数据表 需要一张专门的日志表进行记录, 就是说你写个更新,添加的方法都必须写一遍操作日志,代 ...
- Lodop打印表格带页头页尾 高度是否包含页头页尾
通过设置TableHeightScope,可以实现对ADD_PRINT_TABLE,表格带页头页尾,查看本博客另一篇博文:Lodop打印表格带页头页尾 自动分页每页显示头尾 超文本超过打印项高度,会自 ...
- Tensorflow基本操作理解
1. TensorsTensorFlow的数据中央控制单元是tensor(张量),一个tensor由一系列的原始值组成,这些值被形成一个任意维数的数组.一个tensor的列就是它的维度. 2. The ...
- nginx(三)反向代理和负载均衡
nginx(三)反向代理和负载均衡 正向代理概念:比如在学校要上网,在学校内网是一个内网ip,需要连上公网就需要一个正向代理服务器. 反向代理概念: 看下图(Nginx只做请求的转发,后台有多个htt ...
- Apache服务器配置与管理
一.Apache服务器的目录和文件 1.WEB站点目录 /var/www Apache站点文件的目录 /var/www/html 存放WEB站点的WEB文件 /var/www/cgi-bin CGI程 ...
- BSGS算法
BSGS算法 我是看着\(ppl\)的博客学的,您可以先访问\(ppl\)的博客 Part1 BSGS算法 求解关于\(x\)的方程 \[y^x=z(mod\ p)\] 其中\((y,p)=1\) 做 ...
- java 日期格式化
DateFormat DateFormat 是日期/时间格式化子类的抽象类,它以与语言无关的方式格式化并解析日期或时间. SimpleDateFormat SimpleDateFormat 是一个以与 ...
- python之路day03--数据类型分析,转换,索引切片,str常用操作方法
数据类型整体分析 int :用于计算bool:True False 用户判断str:少量数据的存储 list:列表 储存大量数据 上亿数据[1,2,3,'zzy',[aa]] 元组:只读列表(1,23 ...
- 让WinSCP和Putty一直保持连接
转: 让WinSCP和Putty一直保持连接 2015年08月14日 01:08:19 zcczbq 阅读数:13173 标签: puttywinscp 更多 个人分类: Operation 版权 ...
- crontab 误删恢复
某台服务器某账号的 crontab 任务被清空,原因不明.同时,该服务器上的 crontab 任务备份未开启.故思考如何恢复 crontab 任务. 经查,CentOS 系统的 crontab 任务的 ...