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 ...
随机推荐
- 最全免费CDN公共库——网站提速
开源静态文件 CDN 我们的目标是提供这样一个仓库,让它尽可能全面收录优秀的开源库,并免费为之提供 CDN 加速服务,使之有更好的访问速度和稳定的环境.同时,我们也提供开源库源接入的入口,让所有人都可 ...
- 【转】HTTP
[转]HTTP 一.http概述 超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.所有的WWW文件都必须遵守这个标准.设计HTT ...
- Node.js的单元测试框架初体验
Mocha是一个功能丰富的JavaScript测试框架,运行在node.js平台和浏览器端,使异步测试变得简单和有趣.Mocha测试是串行的,允许灵活和准确的报告,同时将未捕获的异常映射到相应的测试用 ...
- valgrind--内存泄漏检测(转)
Valgrind 概述 体系结构 Valgrind是一套Linux下,开放源代码(GPL V2)的仿真调试工具的集合.Valgrind由内核(core)以及基于内核的其他调试工具组成.内核类似于一个框 ...
- python下载mp4 同步和异步下载支持断点续下
Range 用于请求头中,指定第一个字节的位置和最后一个字节的位置,一般格式: Range:(unit=first byte pos)-[last byte pos] Range 头部的格式有以下几种 ...
- VUE环境部署
npm install vue-router --save 下载node.js安装https://nodejs.org/en/ npm install -g cnpm --registry=http ...
- Win10系统BitLocker解锁后再次快速锁定办法
原文地址:https://blog.csdn.net/ttljtw/article/details/54022241 谁都不愿意把自己电脑上资料完全公开,对资料选择性加密处理是唯一的办法. 微软Win ...
- nginx负载均衡优化配置
针对nginx做负载均衡时其中一台服务器挂掉宕机时响应速度慢的问题解决 nginx会根据预先设置的权重转发请求,若给某一台服务器转发请求时,达到默认超时时间未响应,则再向另一台服务器转发请求. 默认超 ...
- 【原创】大叔经验分享(41)hdfs开启kerberos之后报错Encryption type AES256 CTS mode with HMAC SHA1-96 is not supported/enabled
hdfs开启kerberos之后,namenode报错,连不上journalnode 2019-03-15 18:54:46,504 WARN org.apache.hadoop.security.U ...
- [图形]图形API的两种模式
图形API可以分为retained-mode APIs(保存模式API)和immediate-mode APIs(中间模式API). Direct2D是immediate-mode API,而Wind ...