add web server(nginx)
#!/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)的更多相关文章
- add web server(nginx+apache)
#!/bin/bash # # Web Server Install Script # Last Updated 2012.09.24 # ##### modify by WanJie 2012.09 ...
- NGINX Web Server Nginx web server
原文地址:http://nginx.com/resources/admin-guide/web-server/ NGINX Web Server Nginx web server This secti ...
- delete web server(nginx+apache)
#!/bin/bash conf_dir1="/usr/local/nginx/conf/vhost.d" conf_dir2="/usr/local/apache2/c ...
- 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 ...
- 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 ...
- [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 ...
- virtualbox搭建ubuntu server nginx+mysql+tomcat web服务器1 (未完待续)
virtualbox搭建ubuntu server nginx+mysql+tomcat web服务器1 (未完待续) 第一次接触到 linux,不知道linux的确很强大,然后用virtualbox ...
随机推荐
- Java连接并操作SQLServer数据库
本人只需在项目中引入sqljdbc4.jar 包即可 ----------------------------------------- 在JAVA中如何连接SQL Server数据库 - hangh ...
- vue购物车实战项01
1. 关于挂载点 2.图片路径 这样的引入方式 是直接文件夹下myVue 3.import 不能用绝对路径 只能用相对路径 图片可以绝对路径 4.引入组件步骤 1.引入组件 @的含义在配置里面可以 ...
- ASP.NET MVC - 多国语言的简单实现
定义一个类 public class Book { public int ID { get; set; } public string Title { get; set; } ...
- openstack Q版部署-----Cinder云存储服务(10)
一.cinder介绍 一般 cinder-api 和 cinder-scheduler 安装在控制节点上, cinder-volume 安装在存储节点上. 二.数据库配置 # 在任意控制节点创建数据库 ...
- requests库入门12-文件上传和下载
因为找不到可以演示上传接口,所以只能纯代码了 文件上传 上传文件是在请求中使用files参数,files需要指向一个dict,然后dict里面的键是接口中对应文件名的字段,而值就是打开这个文件读取到内 ...
- UDP可靠传输那些事
有空来论坛走走,发现讨论udp可靠传输又热了起来,有人认为udp高效率,有人认为udp丢包重传机制容易控制,还有朋友搞极限测试,当然也有人推销自己的东西,这里写一点我个人的看法. udp可靠传输其实非 ...
- 【转】vector中erase()的使用注意事项
vector::erase():从指定容器删除指定位置的元素或某段范围内的元素 vector::erase()方法有两种重载形式 如下: iterator erase( iterator _Whe ...
- vmware Harbor 复制功能试用
vmware Harbor 复制功能试用 Harbor基于策略的Docker镜像复制功能,可在不同的数据中心.不同的运行环境之间同步镜像,并提供友好的管理界面,大大简化了实际运维中的镜像管理工作. 功 ...
- 修改.bashrc文件PATH变量错误导致系统大部分命令失效
修改.bashrc环境变量,在文件最后添加openssl变量, 本来应该写 export PATH=$PATH:/usr/local/openssl/bin 误写成 export PATH=/usr/ ...
- MySQL新增多个字段
alter table pic_all add ( `expand1` ), `expand2` ), `expand3` ) );