首页服务器Web服务器 nginx虚拟主机防webshell完美版

nginx虚拟主机防webshell完美版

我们先来看下nginx.conf  server  {    listen       80;    server_name  ;    index index.html index.htm index.php;    root  /data/htdocs/www…

我们先来看下nginx.conf

  server
  {
    listen       80;
    server_name  ;
    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  ;
    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= ../../../../../ ,针对两个不同的网站, , 都会把请求发送给9000处理,而如果先访问那么../../../../../就会变成A网站的根目录地址,然后这时候如果你访问,那么open_basedir仍然是A网站的根目录,但是对于B来说,又是不允许访问的,所以就造成了,第二个站点打开以后会出现no input files,那么有什么解决办法呢?

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

首先,nginx.conf配置如下

 server
  {
    listen       80;
    server_name  ;
    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  ;
    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;
      include fcgi.conf;
    }

}

nginx配置修改了,相对的,php-fpm.conf也要修改

每个站点建一个conf

 

A站点

#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

找到php_defines,添加

/data/htdocs/www.a.com:/tmp:/var/tmp

 

 

 

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

找到php_defines,添加

/data/htdocs/www.b.com:/tmp:/var/tmp

 

找到listen_address,修改为

127.0.0.1:9001   注意这里的端口号

 

最后要修改php-fpm启动脚本

#vi /usr/local/webserver/php/sbin/php-fpm

注释掉原来的 #$php_fpm_BIN --fpm $php_opts,添加

$php_fpm_BIN --fpm --fpm-config /usr/local/webserver/php/etc/www.a.com.conf

$php_fpm_BIN --fpm --fpm-config /usr/local/webserver/php/etc/www.b.com.conf

启动服务

#/usr/local/webserver/php/sbin/php-fpm restart

查看端口

#netstat -tln

 

开了9000 9001分别处理两个站点请求

两个php-cgi主进程加载不同的conf文件,这样就完美解决了虚拟主机webshell能跨目录的问题

当然,启动之前记得conf里面的max_children,开启php-cgi子进程数,相应要减少一些,以免造成内存不足

文章来源:DoDo's Blog
原文地址:

本文来自网络,不代表1号站长-站长学院|资讯交流平台立场。转载请注明出处: https://www.1cn.cc/fwq/web/8007.html
上一篇jpg 木马如何执行 如何防止.JPG类型木马?
下一篇 centos redhat系列对抗ddos之居家必备利器 banip.txt
admin

作者: admin

这里可以再内容模板定义一些文字和说明,也可以调用对应作者的简介!或者做一些网站的描述之类的文字或者HTML!

为您推荐

评论列表()

    联系我们

    联系我们

    0898-88888888

    在线咨询: QQ交谈

    邮箱: email@wangzhan.com

    工作时间:周一至周五,9:00-17:30,节假日休息

    关注微信
    微信扫一扫关注我们

    微信扫一扫关注我们

    关注微博
    返回顶部