Php manages nginx virtual host shell scripts, nginxshell_PHP tutorial

Source: Internet
Author: User
Php manages nginx virtual host shell scripts and nginxshell. Php manages nginx virtual host shell scripts. nginxshell uses php as a shell script, which is very convenient. Of course, we can use php scripts to manage nginx virtual hosts, and manage nginx virtual host shell scripts and nginxshell in php.

Using php as a shell script is very convenient. Of course, we can use the php script to manage the nginx virtual host. The following is the author's script file for your reference.

The code is as follows:
#! /Usr/bin/php-q

Start: fwrite (STDOUT, "=========== Vhost Script ===============\ n ");
Fwrite (STDOUT, "= Choose an operation \ n ");
Fwrite (STDOUT, "= 1. Create 2. Delete 3. Exit \ n ");
Fwrite (STDOUT, "===========================================================\ n ");
$ Operate = trim (fgets (STDIN ));
If ($ operate = 1 ){
Fwrite (STDOUT, "Please Enter a Domain Name :");
$ Domain = trim (fgets (STDIN ));
$ Path = "/home/sites/{$ domain }";
$ Nginx_conf = "/etc/nginx/sites/{$ domain }";
$ Nginx_template = "/etc/nginx/template/site_conf ";
$ Apache_conf = "/etc/httpd/conf/httpd. conf ";
$ Conf_str = "";

// Variable initialization

If (file_exists ($ path) exit ("Domain Existed! \ N ");
Else mkdir ($ path, 0700 );
If (file_exists ($ nginx_conf) exit ("Nginx Config file existed! \ N ");
Else {
$ Conf_str = file_get_contents ($ nginx_template );
}

// Directory detection and configuration file copy

Eval ("\ $ conf_str = \" $ conf_str \";");

$ Succes = file_put_contents ($ nginx_conf, $ conf_str );
If (! $ Succes) exit ("Write Config File Fauile! ");
Else echo "Create Vhost success! \ N ";
Goto start;
// Write the configuration file
}
Else if ($ operate = 2 ){
$ Confs_dir = dir ("/etc/nginx/sites ");
$ Confs_list = array ();
$ Count = 0;
While (false! ==( $ Conf_file = $ confs_dir-> 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)
For (www.111cn.net) each ($ confs_list as $ k => $ v ){
Echo "{$ k}. $ v \ n ";
}
$ Index = trim (fgets (STDIN ));
If (in_array ($ index, array_keys ($ confs_list ))){
Copy ($ confs_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 to site icons is not recorded
Location =/favicon. ico {
Log_not_found off;
Access_log off;
}

Robot does not log access to robots.txt
Location =/robots.txt {
Allow all;
Log_not_found off;
Access_log off;
}

Location = /{
Try_files @ proxy;
}

Location /{
Index index.htm index.html index. php;
Try_files \ $ uri @ proxy;
}

# Matching 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;
}

# Matching images and script files
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;
}
}

From: http://www.111cn.net/phper/php-cy/68199.htm


Nginx VM problems

You are the default virtual host.
For example, if your server IP address is 10.10.10.10, add
Server {
Server_name 10.10.10.10;
Listen 80;
Location /{
Rewrite (. *) http: // The domain name you want to jump;

}

}

Restart your nginx.

My VM space supports linux + nginx + mysql + php (lnmp for short). Can I install the Zhimeng system?

You can install phphow directly on your local lnmp. Just remember the data during the installation process. after reading the instructions, you will use it as long as you have the foundation.

You can also directly install Zhimeng on a vm. The premise is that you do not need to debug it locally. you need to know that Zhimeng is just a CMS. you have to design templates and design webpages.

Using php as a shell script by ghost is very convenient. Of course, we can use the php script to manage the nginx virtual host...

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.