相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
- PHP中opcode緩存簡(jiǎn)單用法分析
- thinkPHP控制器變量在模板中的顯示方法示例
- PHP move_uploaded_file() 函數(shù)(將上傳的文件移動(dòng)到新位置)
- dirname(__FILE__)的含義和應(yīng)用說(shuō)明
- thinkPHP5框架實(shí)現(xiàn)分頁(yè)查詢(xún)功能的方法示例
- PHP中單雙號(hào)與變量
- PHP獲得當(dāng)日零點(diǎn)時(shí)間戳的方法分析
- Laravel ORM對(duì)Model::find方法進(jìn)行緩存示例詳解
- PHP讀寫(xiě)文件高并發(fā)處理操作實(shí)例詳解
- 【CLI】利用Curl下載文件實(shí)時(shí)進(jìn)度條顯示的實(shí)現(xiàn)
php + nginx項(xiàng)目中的權(quán)限詳解
本文給大家介紹的關(guān)于php + nginx項(xiàng)目權(quán)限的相關(guān)內(nèi)容,分享出來(lái)供大家參考學(xué)習(xí),下面來(lái)看看詳細(xì)的介紹:
nginx/php-fpm
進(jìn)程權(quán)限
- 主進(jìn)程用戶(hù)為啟動(dòng)的用戶(hù)
- 子進(jìn)程
1、nginx的用戶(hù)為nginx.conf中配置的用戶(hù)
2、php-fpm的用戶(hù)為php-fpm.conf中配置的用戶(hù)
如:?jiǎn)?dòng)nginx的是root,nginx中配置的user是nginx,那主進(jìn)程就是root,子進(jìn)程就是nginx
處理方式
以下訪問(wèn)均以nginx子進(jìn)程進(jìn)行
靜態(tài)文件
- 步驟:nginx訪問(wèn)/index.html時(shí),nginx會(huì)直接訪問(wèn)對(duì)應(yīng)文件,并將內(nèi)容返回給請(qǐng)求的客戶(hù)端。
- 權(quán)限情況:此時(shí)只需要nginx擁有index.html文件的權(quán)限即可。
php腳本文件
步驟:
- nginx訪問(wèn)/index.php時(shí),nginx為了能夠把正確的腳本處理結(jié)果返回給客戶(hù)端,需要進(jìn)行配置告訴nginx.php是非靜態(tài)文件,需要php腳本解析器進(jìn)行處理后才能返回內(nèi)容。
- 一般來(lái)講會(huì)在nginx配置中加上類(lèi)似fastcgi_pass unix:/var/run/php5-fpm.sock;這樣的配置項(xiàng),指明nginx在遇到訪問(wèn)腳本文件時(shí)需要去找誰(shuí),之后會(huì)訪問(wèn)該文件做到將請(qǐng)求轉(zhuǎn)發(fā)至php-fpm。
- 由php-fpm訪問(wèn)真正的php腳本文件,將結(jié)果返回值nginx,再有nginx將結(jié)果返回至客戶(hù)端。
權(quán)限情況:
- nginx需要有/var/run/php5-fpm.sock文件權(quán)限;
- php-fpm需要有/index.php文件權(quán)限;
用戶(hù)配置位置
nginx用戶(hù)設(shè)置在nginx.conf中第一行的user
php-fpm用戶(hù)設(shè)置在php-fpm.conf中的
- listen.owner = xxx;設(shè)置unix socket用戶(hù)
- user = xxx設(shè)置進(jìn)程啟動(dòng)用戶(hù)
注:以上兩個(gè)配置文件不同的操作系統(tǒng)下文件名略有不同,請(qǐng)根據(jù)自身安裝情況自行判斷。
nginx轉(zhuǎn)發(fā)內(nèi)容到php-fpm不只有/var/run/php5-fpm.sock的方式,在php-fpm.conf中還可以通過(guò)配置改為xxx.xxx.xxx:9000等方式
; The address on which to accept FastCGI requests. ; Valid syntaxes are: ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on ; a specific port; ; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on ; a specific port; ; 'port' - to listen on a TCP socket to all IPv4 addresses on a ; specific port; ; '[::]:port' - to listen on a TCP socket to all addresses ; (IPv6 and IPv4-mapped) on a specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. listen = /var/run/php5-fpm.sock