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 ...
随机推荐
- 第六天-request response\13-request乱码.avi;
疑问:提交为POST时 ,request为什么不放在Post里面处理呢? 服务器已经启动后,修改html的代码不需要重启服务器就可以生效 :超链接中有中文,也是需要像get那样 通过该配置文件可以解决 ...
- Social Grouping for Multi-Target Tracking and Head Pose Estimation in Video(翻译)
0 - ABSTRACT 许多计算机任务在缺少上下文信息的情况下的处理会更加困难.例如,在多相机跟踪任务下,行人可能在不同照相机下面因为有这不同的姿势和灯光条件而看起来很不一样.类似地,在低分辨率高角 ...
- OGG-01168
https://blog.csdn.net/zhrzhl/article/details/21698659
- CF1100D Dasha and Chess
题目地址:CF1100D Dasha and Chess 这是我的第一道交互题 思路不难,主要讲讲这条语句: fflush(stdout); stdout是标准输出的意思.因为有时候,我们输出到std ...
- 虚拟机安装CentOS配置静态IP
在VMware中安装Linux虚拟机后(比如CentOS6.*),不能访问网络,需要配置静态IP.虚拟机中推荐使用NET模式进行网络连接,在虚拟机的工具栏点击编辑>虚拟网络编辑器>NET模 ...
- 【转】MySQL— pymysql and SQLAlchemy
[转]MySQL— pymysql and SQLAlchemy 目录 一.pymysql 二.SQLAlchemy 一.pymysql pymsql是Python中操作MySQL的模块,其使用方法和 ...
- Switch 中参数的范围探讨
switch 语句必须遵循下面的规则: switch 语句中的 expression 必须是一个整型或枚举类型,或者是一个 class 类型,其中 class 有一个单一的转换函数将其转换为整型或枚举 ...
- 使用cstdiofile在vs2010中无法写入中文的问题
在VC2010环境下, 以下代码无法实现使用CStdioFile向文本文件中写入中文(用notepad.exe查看不到写入的中文) CStdioFile file; file.Open(…); fil ...
- 题解-hzy loves segment tree I
Problem 题目概要:给定一棵 \(n\) 个节点的树,点有点权,进行 \(m\) 次路径取\(\max\)的操作,最后统一输出点权 \(n\leq 10^5,m\leq 5\times 10^6 ...
- Equivalent Sets HDU - 3836 2011多校I tarjan强连通分量
题意: 给一些集合 要求证明所有集合是相同的 证明方法是,如果$A∈B$,$B∈A$那么$A=B$成立 每一次证明可以得出一个$X∈Y$ 现在已经证明一些$A∈B$成立 求,最少再证明多少次,就可以完 ...