Php manages nginx virtual host shell scripts

Source: Internet
Author: User
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 ^

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.