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 ...
随机推荐
- Palindromic Numbers LightOJ - 1205
题目大意: 求区间内的回文数个数 题目思路: 数位dp,先枚举前一半数字,然后填上相应的后一半数字. #include<cstdio> #include<cstring> #i ...
- 20165234 《Java程序设计》第七周学习总结
第七周学习总结 教材内容学习 第十一章 JDBC与MySQL数据库 连接数据库: 1. 下载JDBC-MySQL数据库驱动 2. 加载JDBC-MySQL数据库驱动 3. 连接数据库 条件与排序查询: ...
- SpringSecurity实现记住我功能
⒈表单添加 <form action="/authentication/form" method="post"> <table> < ...
- ipconfig命令查ip的时候给别人看有危险吗
知识源:Unit 4: Networking 1 4.1 Networking 1 The Routing of a Packet 网址:https://www.baidu.com/link?url ...
- HDOJ 1004 Let the Balloon Rise (字符串+stl)
题目: Problem Description Contest time again! How excited it is to see balloons floating around. But t ...
- Trickbot增加的远程应用程序凭证抓取功能
来源 https://blog.trendmicro.com/trendlabs-security-intelligence/trickbot-adds-remote-application-cred ...
- 二层环路保护,RRPP多环的配置
作者:邓聪聪 组网需求: 局域网中,由A/B/C/D构成RRPP域1换网络结构,要求环网机构中的任意两条线路中断都不能影响业务. 配置思路: 环路由两部分组成,ring1.ring2,B为环1的主节点 ...
- js判断空字符串、null、undefined、空格、中文空格
代码 function isEmpty(obj) { if (obj === null) return true; if (typeof obj === 'undefined') { return t ...
- tcpdump抓取mysql语句
抓包工具tcpdump的使用,抓取具体的sql语句 [root@test7_chat_api_im ~]# tcpdump -s -l - |strings tcpdump: listening on ...
- 快速安装freeswitch
前不久在Centos 6.4上安装了一台Freeswitch,测试已经OK.为了测试FS 的集群效果,从新在安装一台FS,快速安装的过程如下: 方案一:快速安装前提:不用重新下载Freeswitch. ...