首页 > 网站 > 建站经验 > 正文

nginx虚拟主机防webshell完美版

2019-11-02 16:16:22
字体:
来源:转载
供稿:网友

我们先来看下nginx.conf

  server

  {

    listen       80;

    server_name  www.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;

      include fcgi.conf;

    }

}

  server

  {

    listen       80;

    server_name  www.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;

      include fcgi.conf;

    }

}

nginx在80端口接受到访问请求后,会把请求转发给9000端口的php-cgi进行处理

而如果修改php.ini中open_basedir= ../../../../../ ,针对两个不同的网站,www.a.com , www.b.com都会把请求发送给9000处理,而如果先访问www.a.com那么../../../../../就会变成A网站的根目录地址,然后这时候如果你访问www.b.com,那么open_basedir仍然是A网站的根目录,但是对于B来说,又是不允许访问的,所以就造成了,第二个站点打开以后会出现no input files,那么有什么解决办法呢?

我们可以把不同的虚拟主机发送到不同的php-cgi端口进行处理,当然响应的php-fpm配置文件中的open_basedir也不同。。我们来看看怎么配置。。

首先,nginx.conf配置如下

 server

  {

    listen       80;

    server_name  www.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;

      include fcgi.conf;

    }

}

  server

  {

    listen       80;
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表