add web server(nginx+apache)
#!/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 / { 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://php_pool; expires -1; } } } eof echo "$nginx_rewrite" > $rewrite_dir/$domain.conf cat > $conf_dir2/$domain.conf<<eof <VirtualHost *:8080> ServerName $domain $apache_alias $apache_alias2 UseCanonicalName Off ServerAdmin "admin@wondershare.com" DocumentRoot $web_dir/$domain/httpdocs DirectoryIndex index.html index.shtml index.php CustomLog "|/usr/local/apache2/bin/rotatelogs -l /data/www/logs/apache_log/access/${domain}_access.log.%Y-%m-%d 86400" combined ErrorLog "|/usr/local/apache2/bin/rotatelogs -l /data/www/logs/apache_log/error/${domain}_error.log.%Y-%m-%d 86400" <IfModule mod_ssl.c> SSLEngine off </IfModule> <Directory $web_dir/$domain/httpdocs/> <IfModule sapi_apache2.c> php_admin_flag engine on php_admin_flag safe_mode on php_admin_value open_basedir ".:$web_dir/$domain:/tmp" </IfModule> <IfModule mod_php5.c> php_admin_flag engine on php_admin_flag safe_mode on php_admin_value open_basedir ".:$web_dir/$domain:/tmp" </IfModule> Options -ExecCGI FollowSymLinks +Includes AllowOverride All </Directory> ErrorDocument 404 /404.html $apache_rewrite </VirtualHost> eof 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+apache)的更多相关文章
- add web server(nginx)
#!/bin/bash # # Web Server Install Script # Last Updated 2012.09.24 # ##### modify by WanJie 2012.09 ...
- delete web server(nginx+apache)
#!/bin/bash conf_dir1="/usr/local/nginx/conf/vhost.d" conf_dir2="/usr/local/apache2/c ...
- NGINX Web Server Nginx web server
原文地址:http://nginx.com/resources/admin-guide/web-server/ NGINX Web Server Nginx web server This secti ...
- Build Web Server with Apache and Passenger
Follow the instructions at 2.6. Generic installation, upgrade and downgrade method: via tarball of P ...
- 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 ...
- Web Server 与 App Server
Web Server 常见的Web Server有Apache Server与Nginx. Apache Http Server是Apache软件基金会下的一个项目,是一款开源的HTTP服务器软件(它 ...
- Apache 后台服务器(主要处理php及一些功能请求 如:中文url) Nginx 前端服务器(利用它占用系统资源少得优势来处理静态页面大量请求) Lighttpd 图片服务器 总体来说,随着nginx功能得完善将使他成为今后web server得主流。
Apache 后台服务器(主要处理php及一些功能请求 如:中文url) Nginx 前端服务器(利用它占用系统资源少得优势来处理静态页面大量请求) Lighttpd 图片服务器 总体来说,随着ngi ...
随机推荐
- Shell命令-系统信息及显示之dmesg、uptime
文件及内容处理 - dmesg.uptime 1. dmesg:显示开机信息 dmesg命令的功能说明 dmesg 命令用于显示开机信息.kernel 会将开机信息存储在 ring buffer 中. ...
- AtomicInteger学习
面试时被问到了,补下 import java.util.concurrent.atomic.AtomicInteger; /** * Created by tzq on 2018/7/15. */ p ...
- fedora上安装ffmpeg
环境 fedora26 1. 安装 yasm sudo dnf install yasm yasm-devel -y 2.安装 ffmpeg 官方下载ffmpeg源码 ( http://ffmpeg ...
- 尝试dapper和postgresql
大多数地方和其他数据库(MySQL)没有什么不同.只有几点要注意: 1.PostgreSQL表名和字段是区分大小写的,大小写不对会说字段不存在 2.插入Json数据时,要在字符串后面加上::json ...
- 电脑装windows和ubuntu,如何卸载ubuntu系统
电脑装windows和ubuntu,如何卸载ubuntu系统 2018年01月17日 16:28:29 职业炮灰 阅读数:684 版权声明:本文为博主原创文章,未经博主允许不得转载. https ...
- mpvue——componets中引入vant-weapp组件
前言 这个问题很奇葩,网上也有很多人,给了很多方法,但是我想说的是,那些方法我用了都没效果,我试了一些都没效果,因为我当时引入时报错说没有export default出来,但是一旦暴露出来就又出其他问 ...
- Python【第三篇】文件操作、字符编码
一.文件操作 文件操作分为三个步骤:文件打开.操作文件.关闭文件,但是,我们可以用with来管理文件操作,这样就不需要手动来关闭文件. 实现原理: import contextlib @context ...
- 欧拉筛法模板and 洛谷 P3383 【模板】线性筛素数(包括清北的一些方法)
题目描述 如题,给定一个范围N,你需要处理M个某数字是否为质数的询问(每个数字均在范围1-N内) 输入格式 第一行包含两个正整数N.M,分别表示查询的范围和查询的个数. 接下来M行每行包含一个不小于1 ...
- tomcat8 源码分析 | 组件及启动过程
tomcat 8 源码分析 ,本文主要讲解tomcat拥有哪些组件,容器,又是如何启动的 推荐访问我的个人网站,排版更好看呦: https://chenmingyu.top/tomcat-source ...
- mysql5.7 修改root密码无法登陆原因
升级的mysql5.7修改完root账户密码后仍然无法登陆,查阅资料可能和user表的plugin 字段为空有关. 1.首先将my.ini中加入在[mysqld]节点上加skip-grant-tabl ...