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 ...
随机推荐
- 记录一段QQ关于 UNIGUI 的Session 时间设定
记录一段QQ关于 UNIGUI 的Session 时间设定,来自[台中]cmj(31365722): [重點說明] 1.UniGUI的Session就是UniMainModule. 2.Sess ...
- requests库入门04-http基本认证
因为后续样例中GitHub都需要提供认证,所以先写关于基本认证的 http的请求中,有一些请求是需要通过授权认证之后才会响应,授权认证就是检查用户名和密码的过程.http有一个基本认证方式,在认证的过 ...
- MFC不可不会
这些可能会很抽象,你既然学MFC,给你几个不可少的技术点 1.Dynamic Creation2.Runtime Type Imformation3.Persistence4.Message Mapp ...
- translate.py
#!/usr/bin/python # -*- coding: UTF-8 -*- import xlrd import xlwt from xlutils.copy import copy impo ...
- linux快速将磁盘额外空间扩展到某一挂载点
由于之前在创建用户时,为该用户目录分配的空间只有5G,在后续的开发,存放的东西越来越多,空间眼看就不够用了,网上查了一下,很多都是教我们将其余挂载点分配过多的空间分配到空间不足的挂载点,步骤还不算太复 ...
- VIsual Studio编译OpenCV:无法打开python27_d.lib(python36_d.lib)的问题
原文地址:http://blog.csdn.net/Chris_zhangrx/article/details/78947526 在用 VS2015 编译 Debug 版的 openCV 源码时,最后 ...
- redhat yum
背景 这个redhat可让我好一顿折腾,对于这个yum的安装,如果成功则罢,不成功可有的收拾的.还是centos比较好啊. 转载 1 下载下面四个软件包(可以从163下载,版本号自己搜索) wget ...
- 用Openssl计算ECDSA签名
ECDSA的全名是Elliptic Curve DSA,即椭圆曲线DSA.它是Digital Signature Algorithm (DSA)应用了椭圆曲线加密算法的变种.椭圆曲线算法的原理很复杂, ...
- ubuntu 安装 eclipse 及其CDT
CDT是在eclipse平台上进行c/c++程序开发的插件.首先安装eclipse平台. 1.在Ubuntu 16.04上查看 eclipse是否已经安装: eclipse 若已经安装,则会进入到ec ...
- Linux更新阿里源
阿里云Linux安装镜像源地址:http://mirrors.aliyun.com/ CentOS系统更换软件安装源: 第一步:备份你的原镜像文件,以免出错后可以恢复. mv /etc/yum.rep ...