Nginx virtual host protection webshell perfect Edition

Source: Internet
Author: User

This article is original by DoDo. For more information, see the source: RainyFox.

Let's take a look at nginx. conf.

Server
{
Listen 80;
Server_nameWww.a.com;
Index index.html index.htm index. php;
Root/data/htdocs/www.a.com /;

# Limit_conn crawler 20;

Location ~ . *. (Php | php5 )? $
{
# Fastcgi_pass unix:/tmp/php-cgi.sock;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fcinclude gi. conf;
}

}

Server
{
Listen 80;
Server_nameWww. B .com;
Index index.html index.htm index. php;
Root/data/htdocs/www. B .com /;

# Limit_conn crawler 20;

Location ~ . *. (Php | php5 )? $
{
# Fastcgi_pass unix:/tmp/php-cgi.sock;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fcinclude gi. conf;
}

}

After nginx receives the access request on port 80, it will forward the request to php-cgi on port 9000 for processing.

If you modify open_basedir =.../in php. ini, for two different websites, www.a.com,Www. B .comWill send the request to 9000 for processing, and if you accessWww.a.comThen.../will become the root directory address of website A. If you accessWww. B .comTherefore, open_basedir is still the root directory of website A, but for website B, access is not allowed. Therefore, no input files will appear after the second site is opened, so what are the solutions?

We can send different virtual hosts to different php-cgi ports for processing. Of course, the open_basedir in the php-fpm configuration file in the response is also different .. Let's see how to configure it ..

First, configure nginx. conf as follows:

Server
{
Listen 80;
Server_nameWww.a.com;
Index index.html index.htm index. php;
Root/data/htdocs/www.a.com /;

# Limit_conn crawler 20;

Location ~ . *. (Php | php5 )? $
{
# Fastcgi_pass unix:/tmp/php-cgi.sock;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fcinclude gi. conf;
}

}

Server
{
Listen 80;
Server_nameWww. B .com;
Index index.html index.htm index. php;
Root/data/htdocs/www. B .com /;

# Limit_conn crawler 20;

Location ~ . *. (Php | php5 )? $
{
# Fastcgi_pass unix:/tmp/php-cgi.sock;
Fastcgi_pass 127.0.0.1: 9001;
Fastcgi_index index. php;
Fcinclude gi. conf;
}

}

Note: requests sent from www.a.com are sent to port 9000,Www. B .comRequests sent to port 9001, and so on

Nginx configuration modified, relative, php-fpm.conf also need to modify

Create a conf file for each site

 

Site

# Cp/usr/local/webserver/php/etc/php-fpm.conf/usr/local/webserver/php/etc/www.a.com. conf

# Vi/usr/local/webserver/php/etc/www.a.com. conf

Find php_defines and add

<Value name = "open_basedir">/data/htdocs/www.a.com:/tmp:/var/tmp </value>

 

 

 

Site B

# Cp/usr/local/webserver/php/etc/php-fpm.conf/usr/local/webserver/php/etc/www. B .com. conf

# Vi/usr/local/webserver/php/etc/www. B .com. conf

Find php_defines and add

<Value name = "open_basedir">/data/htdocs/www. B .com:/tmp:/var/tmp </value>

 

 

Locate listen_address and change it

<Value name = "listen_address"> 127.0.0.1:9001</Value>Note the port number here

 

 

Finally, modify the php-fpm STARTUP script.

# Vi/usr/local/

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.