国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php管理nginx虛擬主機shell腳本

2024-05-04 21:49:43
字體:
來源:轉載
供稿:網友

下文整理了一段php管理nginx虛擬主機shell腳本,希望這段腳本能幫助到各位同學,使用php作為shell腳本是一件很方便的事情,理所當然,我們可以使用php腳本來管理 nginx虛擬主機,下面是筆者的 腳本 文件供各位參考,代碼如下:

  1. #!/usr/bin/php -q 
  2. <?php 
  3.  
  4. start: fwrite(STDOUT,"===========Vhost Script===========\n"); 
  5. fwrite(STDOUT,"= Choose an operation \n"); 
  6. fwrite(STDOUT,"= 1.Create 2.Delete 3.Exit\n"); 
  7. fwrite(STDOUT,"==================================\n"); 
  8. $operate = trim(fgets(STDIN)); 
  9. if ( $operate == 1  ){ 
  10. fwrite(STDOUT,"Please Enter a  Domain Name:"); 
  11. $domain = trim(fgets(STDIN)); 
  12. $path = "/home/sites/{$domain}"
  13. $nginx_conf = "/etc/nginx/sites/{$domain}"
  14. $nginx_template = "/etc/nginx/template/site_conf"
  15. $apache_conf = "/etc/httpd/conf/httpd.conf"
  16. $conf_str = ""
  17.  
  18. //變量初始化 
  19.  
  20. iffile_exists($path ) ) exit ("Domain Existed!\n"); 
  21. else mkdir($path,0700); 
  22. if(file_exists($nginx_conf)) exit ("Nginx Config file existed!\n"); 
  23. else { 
  24.     $conf_str = file_get_contents$nginx_template ); 
  25.  
  26. //目錄檢測及配置文件拷貝 
  27.  
  28. eval ( "\$conf_str = \"$conf_str";" ); 
  29.  
  30. $succes = file_put_contents($nginx_conf,$conf_str); 
  31. if( !$succes ) exit ("Write Config File Fauile!"); 
  32. else echo "Create Vhost success!\n"
  33. goto start; 
  34. //寫入配置文件 
  35. else if ($operate == 2){ 
  36.     $confs_dir = dir("/etc/nginx/sites"); 
  37.     $confs_list = array(); 
  38.     $count = 0; 
  39.     while ( false !== ( $conf_file = $confs_dir->read() ) ){ 
  40.         if$conf_file == "." ) continue
  41.         if$conf_file == ".." ) continue
  42.         if ( is_file$confs_dir->path ."/"$conf_file) ) { 
  43.             $confs_list[$count++] =  $conf_file
  44.         } 
  45.     } 
  46.     echo "Select a site by number which to delete:\n"
  47.     ifcount$confs_list ) >0 ) 
  48.         foreach ( $confs_list as $k=>$v ){ 
  49.             echo "{$k}. $v\n"
  50.         } 
  51.     $index = trim(fgets(STDIN)); 
  52.     if( in_array ( $index,array_keys$confs_list ) ) ){ 
  53.         copy(  $confs_dir->path ."/"$confs_list[$index],"/etc/nginx/backup/{$confs_list[$index]}" ); 
  54.         unlink ( $confs_dir->path ."/"$confs_list[$index] ); 
  55.         exec("tar -zcf  /home/sites/{$confs_list[$index]}.tar.gz /home/sites/".$confs_list[$index] ); 
  56.         exec("rm -Rf /home/sites/".$confs_list[$index]); 
  57.     } //開源軟件:Vevb.com 
  58.     //刪除指定配置,并保存備份 
  59. else if$operate == 3 ) { 
  60.     exit
  61. else { 
  62.  exit ("No Operation Selected!"); 
  63. }?> 

下面是nginx的配置模版,代碼如下:

  1. server { 
  2. listen 80; 
  3. server_name {$domain}; 
  4. access_log /var/log/nginx/{$domain}_access_log; 
  5. error_log /var/log/nginx/{$domain}_error_log; 
  6. root {$path}; 
  7. #不記錄對站點圖標訪問 
  8. location = /favicon.ico { 
  9. log_not_found off; 
  10. access_log off; 
  11. #不記錄對robots.txt的訪問 
  12. location = /robots.txt { 
  13. allow all; 
  14. log_not_found off; 
  15. access_log off; 
  16. location = / { 
  17. try_files @proxy; 
  18. location / { 
  19. index index.htm index.html index.php; 
  20. try_files \$uri @proxy; 
  21. #匹配html 
  22. location ~* \.(html|htm)$ { 
  23. expires 30s; 
  24. gzip off; 
  25. add_header Content-Encoding gzip; 
  26. try_files \$uri \$uri/ /wp-content/cache/supercache/\$http_host/\$request_uri/index.html.gz @proxy; 
  27. #匹配圖片、腳本文件等 
  28. location ~* \.(jpe?g|gif|png|ico|css|js|flv|swf|avi|zip|rar|svg|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mp3)$ { 
  29. expires 30d; 
  30. #傳遞給apache 
  31. location @proxy { 
  32. index index.htm index.html index.php; 
  33. proxy_pass   http://127.0.0.1:81; 
  34. include /etc/nginx/proxy.conf; 
  35. }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 都江堰市| 鄱阳县| 开鲁县| 蚌埠市| 天津市| 阳谷县| 奈曼旗| 花莲县| 芮城县| 葫芦岛市| 通化县| 综艺| 隆尧县| 保德县| 内江市| 舒城县| 房产| 晋江市| 时尚| 宁远县| 河南省| 绥德县| 杨浦区| 剑阁县| 灵台县| 宜春市| 阿坝| 东阳市| 禹州市| 林芝县| 崇文区| 西贡区| 连江县| 都江堰市| 阳江市| 雅安市| 惠来县| 嘉兴市| 图片| 安福县| 康乐县|