The following is a php shell script for managing nginx virtual hosts. I hope this script will help you to use php as a shell script, we can use php scripts to manage nginx virtual hosts... the following is a php shell script for managing nginx virtual hosts. I hope this script will help you to use php as a shell script, we can use the php script to manage the nginx virtual host. The following is the script file for your reference. the code is as follows:
#! /Usr/bin/php-q
Read () {if ($ conf_file = ". ") continue; if ($ conf_file = ".. ") continue; if (is_file ($ confs_dir-> path. "/". $ conf_file) {$ confs_list [$ count ++] = $ conf_file;} echo "Select a site by number which to delete: \ n "; if (count ($ confs_list)> 0) foreach ($ confs_list as $ k => $ v) {echo "{$ k }. $ v \ n ";}$ index = trim (fgets (STDIN); if (in_array ($ index, array_keys ($ confs_list) {copy ($ c Onfs_dir-> path. "/". $ confs_list [$ index], "/etc/nginx/backup/{$ confs_list [$ index]}"); unlink ($ confs_dir-> path. "/". $ confs_list [$ index]); exec ("tar-zcf/home/sites/{$confs_list?#index=#.tar.gz/home/sites /". $ confs_list [$ index]); exec ("rm-Rf/home/sites /". $ confs_list [$ index]);} // delete the specified configuration and save the backup} else if ($ operate = 3) {exit ;} else {exit ("No Operation Selected! ");}
The following is the nginx configuration template. the code is as follows:
Server {listen 80; server_name {$ domain}; access_log/var/log/nginx/{$ domain} _ access_log; error_log/var/log/nginx/{$ domain} _ error_log; root {$ path}; # access location =/favicon to site icons is not recorded. ico {log_not_found off; access_log off;} failover does not record the access location to robots.txt =/robots.txt {allow all; log_not_found off; access_log off;} location =/{try_files @ proxy ;} location/{index index.htm index.html index. ph P; try_files \ $ uri @ proxy;} # match html location ~ *\. (Html | htm) $ {expires 30 s; gzip off; add_header Content-Encoding gzip; try_files \ $ uri // wp-content/cache/supercache/\ $ http_host/\ $ request_uri/index.html.gz @ proxy;} # match images, script files, and other 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) $ {expires 30d;} # pass to apache location @ proxy {index index.htm index.html index. php; proxy_pass http: // 127.0.0.1: 81; include/etc/nginx/proxy. conf ;}}
Permanent address:
Reprint at will ~ Please bring the tutorial URL ^