#!/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. python - 爬虫入门练习 爬取链家网二手房信息

    import requests from bs4 import BeautifulSoup import sqlite3 conn = sqlite3.connect("test.db&qu ...

  2. Django中的缓存基础知识

    由于Django是动态网站,所有每次请求均会去数据进行相应的操作,当程序访问量大时,耗时必然会更加明显,最简单解决方式是使用:缓存,缓存将一个某个views的返回值保存至内存或者memcache中,5 ...

  3. spring3.2.2 remoting HTTP invoker 实现方式

    最近跟朋友聊天,聊到他们现在项目的架构都是把数据层跟应用层分离开来,中间可以加memcached等的缓存系统,感觉挺好的,很大程度上的降低耦合,然后还明确分配了数据层跟应用层任务.也方便定位.找到问题 ...

  4. pytroch 0.3 到 0.4版本迁移资料mark

    搜了一堆,还是官方资料给力,一份中文,一份英文,maek一下 https://www.pytorchtutorial.com/pytorch-0-4-0-migration-guide/ https: ...

  5. 【转】python模块分析之unittest测试(五)

    [转]python模块分析之unittest测试(五) 系列文章 python模块分析之random(一) python模块分析之hashlib加密(二) python模块分析之typing(三) p ...

  6. pt-table-checksum 使用方法【转】

    27. pt-table-checksum27.1 pt-table-checksum 作用 主要用来检查主从数据是否一致,原理即在主库执行把表每行的列通过concat函数进行拼接,然后对拼接的值进行 ...

  7. NUMA的关闭方法【转】

    Centos 6 在/etc/grub.conf    在kernel 添加numa=off 就行了 一.检查OS是否开启NUMA # numactl --hardware available: 1 ...

  8. 计算机中内存、cache和寄存器之间的关系及区别

    1. 寄存器是中央处理器内的组成部份.寄存器是有限存贮容量的高速存贮部件,它们可用来暂存指令.数据和位址.在中央处理器的控制部件中,包含的寄存 器有指令寄存器(IR)和程序计数器(PC).在中央处理器 ...

  9. jQuery.extend()参数

    非原创,转载仅供学习 在处理插件参数的接收上,通常使用jQuery的extend方法.extend方法传递单个对象的情况下,这个对象会合并到jQuery身上,而当用extend方法传递一个以上的参数时 ...

  10. FS G729转码测试记录

    默认情况下Freeswitch自带的G729模块是pass-through-并不支持转码.我们决定添加一个支持G729转码的模块到Freeswitch.参考自 8000HZ. 一.安装支持转码的G72 ...