關於php + nginx項目中的許可權詳解

來源:互聯網
上載者:User
這篇文章主要給大家介紹了關於php + nginx項目中許可權的相關資料,文章介紹的非常詳細,對大傢具有一定的參考學習價值,需要的朋友們下面來一起看看吧。

nginx/php-fpm

進程許可權

  • 主進程使用者為啟動的使用者

  • 子進程

1、nginx的使用者為nginx.conf中配置的使用者

2、php-fpm的使用者為php-fpm.conf中配置的使用者

如:啟動nginx的是root,nginx中配置的user是nginx,那主進程就是root,子進程就是nginx

處理方式

以下訪問均以nginx子進程進行

靜態檔案

  • 步驟:nginx訪問/index.html時,nginx會直接存取對應檔案,並將內容返回給請求的用戶端。

  • 許可權情況:此時只需要nginx擁有index.html檔案的許可權即可。

php指令檔

步驟:

  • nginx訪問/index.php時,nginx為了能夠把正確的指令碼處理結果返回給用戶端,需要進行配置告訴nginx.php是非靜態檔案,需要php指令碼解析器進行處理後才能返回內容。

  • 一般來講會在nginx配置中加上類似fastcgi_pass unix:/var/run/php5-fpm.sock;這樣的配置項,指明nginx在遇到訪問指令檔時需要去找誰,之後會訪問該檔案做到將請求轉寄至php-fpm。

  • 由php-fpm訪問真正的php指令檔,將結果傳回值nginx,再有nginx將結果返回至用戶端。

許可權情況:

  • nginx需要有/var/run/php5-fpm.sock檔案許可權;

  • php-fpm需要有/index.php檔案許可權;

使用者配置位置

nginx使用者佈建在nginx.conf中第一行的user

php-fpm使用者佈建在php-fpm.conf中的

  • listen.owner = xxx;設定unix socket使用者

  • user = xxx設定進程啟動使用者

註:以上兩個設定檔不同的作業系統下檔案名稱略有不同,請根據自身安裝情況自行判斷。

nginx轉寄內容到php-fpm不只有/var/run/php5-fpm.sock的方式,在php-fpm.conf中還可以通過配置改為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

其他

比較特別的點,一般nginx都是用root使用者啟動的(為了擷取80連接埠許可權),如果本地開發nginx是用普通使用者重啟,那麼主進程和子進程都會是目前使用者,nginx.conf中的配置不再起效,暫不清楚原因。

相關推薦:

PHP 網站如何修改預設訪問檔案的nginx配置-執行個體分析

nginx內php動態裁剪圖片步驟詳解

php nginx實現即時輸出步驟詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.