目录
nginx降权启动
确认普通用户无法开启nginx
创建普通用户:
测试是否可以启动nginx:
创建必须的相关文件
使用root用户copy配置文件中网页支持类型文件
使用root用户拷贝nginx配置文件
设置权限
修改配置文件
安装 PHP 7.4,配合 Nginx
安装 PHP 和 PHP FPM 软件包:
修改配置文件
root@ubuntu:~# useradd -d /home/test -m test
root@ubuntu:~# passwd test
New password:
Retype new password:
passwd: password updated successfully
root@ubuntu:~#
切换到test用户:
启动失败
$ mkdir nginx
$ cd nginx
$ mkdir conf logs www sbin
root@ubuntu:/www/env/nginx/conf# cp /www/env/nginx/conf/mime.types /home/test/nginx/conf/
root@ubuntu:~# cp /www/env/nginx/conf/nginx.conf /home/test/nginx/conf/
root@ubuntu:~# chown -R test:test /www/env/nginx/
# 将当前前目录下的所有文件与子目录的拥有者皆设为 test,群体的使用者 test:
worker_processes 4;user test test;
pid /home/test/nginx/logs/nginx.pid;
error_log /home/test/nginx/logs/error.log;events {worker_connections 10240;
}
server {root /home/test/www;
}
不能用80特权端口,前端nginx反向代理转端口在启动的时候指定配置文件,普通用户只能用1024以上的端口。
apt install php-fpm
检查服务状态,运行:
systemctl status php7.4-fpm
server {listen 80;root /var/www/html;index index.php index.html index.htm;server_name example.com;location / {try_files $uri $uri/ =404;}location ~ \.php$ {include snippets/fastcgi-php.conf;fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;}
}