码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • nginx降权+匹配php


    目录

    nginx降权启动

    确认普通用户无法开启nginx

     创建普通用户:

     测试是否可以启动nginx:

    创建必需的相关文件

    使用root用户copy配置文件中网页支持类型文件

    使用root用户拷贝nginx配置文件

    设置权限

     修改配置文件

    安装 PHP 7.4,配合 Nginx

    安装 PHP 和 PHP FPM 软件包:

    修改权限 

    配置php-fpm

    修改Nginx配置文件

    测试: 

    在/www/env/nginx/html下创建index.php文件:

    打开浏览器:


    nginx降权启动

    确认普通用户无法开启nginx

     创建普通用户:

    1. root@ubuntu:~# useradd -d /home/test -m test
    2. root@ubuntu:~# passwd test
    3. New password:
    4. Retype new password:
    5. passwd: password updated successfully
    6. root@ubuntu:~#

    切换到test用户: 

     测试是否可以启动nginx:

     启动失败

    创建必需的相关文件

    1. $ mkdir nginx
    2. $ cd nginx
    3. $ mkdir conf logs www sbin

    使用root用户copy配置文件中网页支持类型文件

    root@ubuntu:/www/env/nginx/conf# cp /www/env/nginx/conf/mime.types /home/test/nginx/conf/
    

    使用root用户拷贝nginx配置文件

    root@ubuntu:~# cp /www/env/nginx/conf/nginx.conf /home/test/nginx/conf/

    设置权限

    1. root@ubuntu:~# chown -R test:test /www/env/nginx/
    2. # 将当前前目录下的所有文件与子目录的拥有者皆设为 test,群体的使用者 test:

     修改配置文件

    1. worker_processes 4;
    2. worker_rlimit_nofile 65535;
    3. error_log /home/test/nginx/logs/error.log;
    4. user test test;
    5. pid /home/test/nginx/logs/nginx.pid;
    6. events {
    7. use epoll;
    8. worker_connections 1024;
    9. }
    10. http {
    11. include /home/test/nginx/conf/mime.types;
    12. default_type application/octet-stream;
    13. sendfile on;
    14. keepalive_timeout 65;
    15. server {
    16. listen 8080;
    17. server_name localhost;
    18. root /home/test/nginx/www;
    19. location / {
    20. index index.html index.htm;
    21. }
    22. error_page 500 502 503 504 /50x.html;
    23. location = /50x.html {
    24. root html;
    25. }
    26. access_log /home/test/nginx/logs/access.log;
    27. }

    全路径启动nginx -c参数使用指定的配置文件而不是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

    检查服务状态,运行:

    systemctl status php7.4-fpm

    修改权限 

    chmod 777 /run/php/php7.2-fpm.sock
    

    配置php-fpm

    修改配置监听9000端口来处理nginx的请求(这种方法一般在windows上使用),
    打开 /etc/php/7.2/fpm/pool.d/www.conf 文件找到如下位置注释第一行添加第二行

    1. ;listen = /run/php/php7.2-fpm.sock
    2. listen = 127.0.0.1:9000

    修改Nginx配置文件

    找到下面这部分代码取消注释,修改配置

    1. location ~ \.php$ {
    2. root html;
    3. fastcgi_pass 127.0.0.1:9000;
    4. fastcgi_index index.php;
    5. fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    6. include fastcgi.conf;
    7. }

    测试: 

    在/www/env/nginx/html下创建index.php文件:

    1. root@ubuntu:/www/env/nginx/html# cat index.php
    2. phpinfo()
    3. ?>

    打开浏览器:

  • 相关阅读:
    制作一个简单HTML电影网页设计(HTML+CSS)
    qt Rectangle 使用Gradient设置渐变方向 制作渐变进度条
    金融行业容器平台建设方案
    JAVA毕业设计酒店预约及管理系统计算机源码+lw文档+系统+调试部署+数据库
    【树状数组该回炉重造了】Codeforces Round #813 (Div. 2) E2. LCM Sum (hard version)
    推进智慧工地建设,智慧工地是什么?建筑工地人必看!
    SpringMVC:RESTful案例
    有c语言的基础学习python【python基础详解】
    bash: redi-cli: 未找到命令...
    【svn】svn分支(branch)如何同步主干(trunk)的代码?
  • 原文地址:https://blog.csdn.net/weixin_59280309/article/details/127928961
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号