nginx降權(quán)與匹配php詳細(xì)講解
nginx降權(quán)啟動(dòng)
確認(rèn)普通用戶(hù)無(wú)法開(kāi)啟nginx

創(chuàng)建普通用戶(hù):
root@ubuntu:~# useradd -d /home/test -m test root@ubuntu:~# passwd test New password: Retype new password: passwd: password updated successfully root@ubuntu:~#
切換到test用戶(hù):

測(cè)試是否可以啟動(dòng)nginx:

啟動(dòng)失敗
創(chuàng)建必需的相關(guān)文件
$ mkdir nginx $ cd nginx $ mkdir conf logs www sbin
使用root用戶(hù)copy配置文件中網(wǎng)頁(yè)支持類(lèi)型文件
root@ubuntu:/www/env/nginx/conf# cp /www/env/nginx/conf/mime.types /home/test/nginx/conf/
使用root用戶(hù)拷貝nginx配置文件
root@ubuntu:~# cp /www/env/nginx/conf/nginx.conf /home/test/nginx/conf/

設(shè)置權(quán)限
root@ubuntu:~# chown -R test:test /www/env/nginx/ # 將當(dāng)前前目錄下的所有文件與子目錄的擁有者皆設(shè)為 test,群體的使用者 test:
修改配置文件
worker_processes 4;
worker_rlimit_nofile 65535;
error_log /home/test/nginx/logs/error.log;
user test test;
pid /home/test/nginx/logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include /home/test/nginx/conf/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
root /home/test/nginx/www;
location / {
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
access_log /home/test/nginx/logs/access.log;
}
全路徑啟動(dòng)nginx -c參數(shù)使用指定的配置文件而不是conf目錄下的nginx.conf
/www/env/nginx/sbin/nginx -c /home/test/nginx/conf/nginx.conf &> /dev/null
安裝 PHP 7.4,配合 Nginx
安裝 PHP 和 PHP FPM 軟件包:
apt install php-fpm
檢查服務(wù)狀態(tài),運(yùn)行:
systemctl status php7.4-fpm
修改權(quán)限
chmod 777 /run/php/php7.2-fpm.sock
配置php-fpm
修改配置監(jiān)聽(tīng)9000端口來(lái)處理nginx的請(qǐng)求(這種方法一般在windows上使用),打開(kāi) /etc/php/7.2/fpm/pool.d/www.conf 文件找到如下位置注釋第一行添加第二行
;listen = /run/php/php7.2-fpm.sock listen = 127.0.0.1:9000
修改Nginx配置文件
找到下面這部分代碼取消注釋?zhuān)薷呐渲?/p>
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}測(cè)試:
在/www/env/nginx/html下創(chuàng)建index.php文件:
root@ubuntu:/www/env/nginx/html# cat index.php <?php phpinfo() ?>
打開(kāi)瀏覽器:

總結(jié)
到此這篇關(guān)于nginx降權(quán)與匹配php的文章就介紹到這了,更多相關(guān)nginx降權(quán) 匹配php內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
windows系統(tǒng)下關(guān)閉Nignx的多種方式總結(jié)
這篇文章主要給大家總結(jié)介紹了windows系統(tǒng)下關(guān)閉Nignx的多種方式, 在Windows中啟動(dòng)Nginx是簡(jiǎn)單的,但有許多小伙伴不會(huì)關(guān)閉,這里給大家介紹下,需要的朋友可以參考下2023-08-08
Nginx實(shí)現(xiàn)動(dòng)態(tài)封禁IP的設(shè)計(jì)方案
為了封禁某些爬蟲(chóng)或者惡意用戶(hù)對(duì)服務(wù)器的請(qǐng)求,我們需要建立一個(gè)動(dòng)態(tài)的 IP 黑名單,對(duì)于黑名單中的 IP ,我們將拒絕提供服務(wù),并且可以設(shè)置封禁失效時(shí)間,所以本文給大家介紹了Nginx實(shí)現(xiàn)動(dòng)態(tài)封禁IP的設(shè)計(jì)方案,需要的朋友可以參考下2024-12-12
nginx?80端口配置多個(gè)location無(wú)效訪問(wèn)404問(wèn)題
這篇文章主要介紹了nginx?80端口配置多個(gè)location無(wú)效訪問(wèn)404問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06
Nginx服務(wù)器下使用rewrite重寫(xiě)url以實(shí)現(xiàn)偽靜態(tài)的示例
這篇文章主要介紹了Nginx服務(wù)器下使用rewrite重寫(xiě)url以實(shí)現(xiàn)偽靜態(tài)的示例,這里舉了Discuz!和WordPress這兩個(gè)常用的PHP程序,需要的朋友可以參考下2015-12-12
簡(jiǎn)單談?wù)凬ginx基礎(chǔ)知識(shí)入門(mén)
Nginx(engine x)是一個(gè)高性能的HTTP服務(wù)器(其實(shí)不止HTTP服務(wù)器),一般主要用作負(fù)載均衡和反向代理,今天我們來(lái)簡(jiǎn)單學(xué)習(xí)下他的基礎(chǔ)配置知識(shí)2017-08-08

