亚洲韩日午夜视频,欧美日韩在线精品一区二区三区,韩国超清无码一区二区三区,亚洲国产成人影院播放,久草新在线,在线看片AV色

您好,歡迎來到思海網(wǎng)絡(luò),我們將竭誠為您提供優(yōu)質(zhì)的服務(wù)! 誠征網(wǎng)絡(luò)推廣 | 網(wǎng)站備案 | 幫助中心 | 軟件下載 | 購買流程 | 付款方式 | 聯(lián)系我們 [ 會(huì)員登錄/注冊 ]
促銷推廣
客服中心
業(yè)務(wù)咨詢
有事點(diǎn)擊這里…  531199185
有事點(diǎn)擊這里…  61352289
點(diǎn)擊這里給我發(fā)消息  81721488
有事點(diǎn)擊這里…  376585780
有事點(diǎn)擊這里…  872642803
有事點(diǎn)擊這里…  459248018
有事點(diǎn)擊這里…  61352288
有事點(diǎn)擊這里…  380791050
技術(shù)支持
有事點(diǎn)擊這里…  714236853
有事點(diǎn)擊這里…  719304487
有事點(diǎn)擊這里…  1208894568
有事點(diǎn)擊這里…  61352289
在線客服
有事點(diǎn)擊這里…  531199185
有事點(diǎn)擊這里…  61352288
有事點(diǎn)擊這里…  983054746
有事點(diǎn)擊這里…  893984210
當(dāng)前位置:首頁 >> 技術(shù)文章 >> 文章瀏覽
技術(shù)文章

Nginx+PHP的虛擬主機(jī)目錄權(quán)限控制的探究

添加時(shí)間:2015-7-12 0:22:12  添加: 思海網(wǎng)絡(luò) 
Nginx的使用者最近越來越多,很多大型網(wǎng)站也都從Apache或其他平臺遷移到了Nginx。但在我使用Nginx的過程中有個(gè)問題一直未得到解決,就是如何限制Nginx+PHP的目錄權(quán)限

我們知道,在Apache中可以很容易的對虛擬目錄進(jìn)行權(quán)限控制,如:

<VirtualHost www.xpb.cn>

    ServerAdmin xiaopb@live.com

    DocumentRoot /usr/www/xpb/

    ServerName www.xpb.cn:80

    ServerAlias www.xpb.cn

    ErrorLog logs/default-error_log

    php_admin_value open_basedir "/tmp/:/usr/www/xpb/"

</VirtualHost>

關(guān)鍵是后面的這句php_admin_value,這樣就限制了php的操作目錄僅限于/tmp/和/usr/www/xpb/這兩個(gè)目錄了。對于Apache虛擬主機(jī)來說,這個(gè)設(shè)置十分有用,結(jié)合在php.ini中禁用一些php函數(shù),幾乎可以杜絕PHP木馬對其他站點(diǎn)及系統(tǒng)的危害。我雖沒專業(yè)做過Linux下的虛擬主機(jī),但相信各大虛擬主機(jī)商也是這么做的。

 

    看來對于Apache最好的辦法還是使用“在php.ini中禁用一些危險(xiǎn)的php函數(shù)和在Apache虛擬主機(jī)中配置php_admin_value”的方式來做虛擬主機(jī)的安全。

 

   關(guān)于Nginx的配置文件,參考了很多資料,好像是不支持php_admin_value open_basedir,也就是Nginx暫時(shí)還沒有Apache的php_myadmin_value這類的設(shè)置。如果用Nginx做虛擬主機(jī),各用戶之間的目錄安全控制如何來做呢?網(wǎng)上很多人說,限制上傳文件類型,做好程序安全不就行了么?對,對于自己的站點(diǎn)來說這樣完全可以。但如果虛擬主機(jī)是給別人用的,又給予了FTP權(quán)限,總不能不讓人上傳php 文件吧。參考以上,如果用Nginx來做虛擬主機(jī),目前看來安全的配置方法是:

 

、用低權(quán)限賬號運(yùn)行Nginx。

 

2、在php.ini中禁用危險(xiǎn)的函數(shù)。如:system,passthru,shell_exec,exec,popen,proc_open,chroot,scandir,chgrp,chown等,但禁止太多的函數(shù)可能對某些php程序的正常運(yùn)行產(chǎn)生影響。

 

3、在php.ini中設(shè)置open_basedir,如:open_basedir = "/usr/local/webserver/nginx /html/www.xpb.cn_7da347bc1a9fd621/:/usr/local/webserver/nginx/html/www2.xpb.cn_7da347bc1a9fd621/"

 

4、各個(gè)虛擬主機(jī)用戶放在不易于猜到的目錄,如:www.xpb.cn_7da347bc1a9fd621、www2.xpb.cn_7da347bc1a9fd621

 

5、自己找一個(gè)php木馬,自我測試服務(wù)器安全!

 

6   在運(yùn)行spawn-fcgi 的時(shí)候帶上參數(shù)-d open_basedir 即可,例如:/usr /sbin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 20 -u www -f "/usr/sbin/php-cgi -d open_basedir=/var/www/wwwroot/:/tmp/"

 

7   先來看兩份配置文件的部分,只跟大家講原理,省略了和主題無關(guān)的部分,請勿復(fù)制就用,明白了原理,就知道該怎么做了。

 

php.ini

; open_basedir, if set, limits all file operations to the defined directory

; and below.  This directive makes most sense if used in a per-directory

; or per-virtualhost web server configuration file. This directive is

; *NOT* affected by whether Safe Mode is turned On or Off.

open_basedir = "/myserver/:/tmp/:/var/tmp/"

nginx.conf

http

{

         server

        {

                listen 80;

                server_name  host1.com;

                root /myserver/host1;

 

                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  host2.com;

       root /myserver/host2;

 

                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  host3.com;

                root /myserver/host3;

 

                location ~ .*/.(php|php5)?$

                {

                         #fastcgi_pass  unix:/tmp/php-cgi.sock;

                         fastcgi_pass  127.0.0.1:9000;

                         fastcgi_index index.php;

                         include fcgi.conf;

                }

        }

}

配置的基本情況是 運(yùn)行3個(gè)網(wǎng)站host1.com  host2.com host3.com  ,php.ini的配置,限制php腳本只能在這三個(gè)網(wǎng)站目錄的父目錄/myserver/ 下面執(zhí)行。

 

這時(shí)候我們知道,如果在某一個(gè)站點(diǎn)上上傳了一個(gè)php木馬,那么這個(gè)木馬將可以訪問其他兩個(gè)站點(diǎn)的文件。nignx 沒有apache那樣能夠單獨(dú)設(shè)置每個(gè)網(wǎng)站的php只能在本目錄下訪問的功能。這時(shí)候我們就要用一點(diǎn)取巧的辦法了。

 

來看這個(gè)php.ini的配置。

open_basedir = "/myserver/:/tmp/:/var/tmp/"

其實(shí)這個(gè)路徑也支持(.) [一個(gè)點(diǎn)] 和(..) [兩個(gè)點(diǎn)],也就是當(dāng)前目錄、父目錄。于是有下面的配置方法

 

open_basedir = ".:/tmp/:/var/tmp/"  把php文件限制在當(dāng)前目錄,的確,這樣確實(shí)是訪問不到別的兩個(gè)網(wǎng)站的目錄了,但是訪問某些頁面會(huì)出現(xiàn)No input file specified. 。

 

為什么呢,因?yàn)樯厦娴倪@個(gè)限制,當(dāng)你運(yùn)行或者引用了網(wǎng)站目錄下的子目錄(或者子目錄的子目錄....)里的php文件(假定為/myserver /host1/dir1/myphp.php),而這個(gè)子目錄文件又要訪問上級目錄里的文件(/myserver/host1/config.php),這時(shí)候問題就來了,php.ini里設(shè)置了myphp.php只能訪問該本級目錄(/myserver/host1/dir1/)以下的文件,而不能訪問/myserver/host1下的直接文件,于是提示:No input file specified.

 

現(xiàn)在解決辦法來了:lol

 

再看兩個(gè)配置文件:

 

下面的這個(gè)/subX1/subX2/subX3/..........(N層) ,N為你網(wǎng)站上最底層的php文件嵌套級數(shù),如果你網(wǎng)站最多有5級子目錄下有php文件,那么就嵌套5層以上。

 

php.ini

; open_basedir, if set, limits all file operations to the defined directory

; and below.  This directive makes most sense if used in a per-directory

; or per-virtualhost web server configuration file. This directive is

; *NOT* affected by whether Safe Mode is turned On or Off.

open_basedir = "../../.......(N層):/tmp/:/var/tmp/"

nginx.conf

http

{

         server

        {

                listen 80;


        server_name  host1.com;

                root /myserver/subA1/subA2/subA3/..........(N層)/host1;

 

                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  host2.com;

                root /myserver/subB1/subB2/subB3/..........(N層)/host2;

 

                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 www.2cto.com

        {

                listen 80;

                server_name  host3.com;

                root /myserver/subC1/subC2/subC3/..........(N層)/host3;

 

                location ~ .*/.(php|php5)?$

                {

                         #fastcgi_pass  unix:/tmp/php-cgi.sock;

                         fastcgi_pass  127.0.0.1:9000;

                         fastcgi_index index.php;

                         include fcgi.conf;

                }

        }

}

舉例N等于5....運(yùn)行,當(dāng)訪問最底層的php文件/myserver/subA1/subA2/subA3/subA4/subA5/host1 /dir1/dir2/dir3/dir4/myphp.php,這個(gè)php文件所能訪問的上級層到/myserver/subA1/subA2 /subA3/subA4/subA5/host1,當(dāng)訪問/myserver/subA1/subA2/subA3/subA4/subA5 /host1/myphp2.php 文件時(shí)候,它所能最多訪問到的上級層/myserver/subA1 ,不能躍出訪問到其他站目錄里的文件

 

這樣就限制了該站目錄下的php程序不能訪問別的網(wǎng)站,而對自己網(wǎng)站的訪問又充分不受限制

關(guān)鍵字:Nginx、PHP、虛擬主機(jī)

分享到:

頂部 】 【 關(guān)閉
版權(quán)所有:佛山思海電腦網(wǎng)絡(luò)有限公司 ©1998-2024 All Rights Reserved.
聯(lián)系電話:(0757)22630313、22633833
中華人民共和國增值電信業(yè)務(wù)經(jīng)營許可證: 粵B1.B2-20030321 備案號:粵B2-20030321-1
網(wǎng)站公安備案編號:44060602000007 交互式欄目專項(xiàng)備案編號:200303DD003  
察察 工商 網(wǎng)安 舉報(bào)有獎(jiǎng)  警警  手機(jī)打開網(wǎng)站