这篇文章主要给大家介绍了关于php + nginx项目中权限的相关资料,文章介绍的非常详细,对大家具有一定的参考学习价值,需要的朋友们下面来一起看看吧。
本文给大家介绍的关于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的权限的详细内容。更多信息请关注PHP中文网其他相关文章!

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

使用依赖注入(DI)的原因是它促进了代码的松耦合、可测试性和可维护性。1)使用构造函数注入依赖,2)避免使用服务定位器,3)利用依赖注入容器管理依赖,4)通过注入依赖提高测试性,5)避免过度注入依赖,6)考虑DI对性能的影响。

phperformancetuningiscialbecapeitenhancesspeedandeffice,whatevitalforwebapplications.1)cachingwithapcureduccureducesdatabaseloadprovesrovesponsemetimes.2)优化

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

TOOPTIMIZEPHPAPPLICITIONSFORPERSTORANCE,USECACHING,数据库imization,opcodecaching和SererverConfiguration.1)InlumentCachingWithApcutCutoredSatfetchTimes.2)优化的atabasesbasesebasesebasesbasesbasesbaysbysbyIndexing,BeallancingAndWriteExing

依赖性注射inphpisadesignpatternthatenhancesFlexibility,可检验性和ManiaginabilybyByByByByByExternalDependencEctenceScoupling.itallowsforloosecoupling,EasiererTestingThroughMocking,andModularDesign,andModularDesign,butquirscarecarefulscarefullsstructoringDovairing voavoidOverOver-Inje

PHP性能优化可以通过以下步骤实现:1)在脚本顶部使用require_once或include_once减少文件加载次数;2)使用预处理语句和批处理减少数据库查询次数;3)配置OPcache进行opcode缓存;4)启用并配置PHP-FPM优化进程管理;5)使用CDN分发静态资源;6)使用Xdebug或Blackfire进行代码性能分析;7)选择高效的数据结构如数组;8)编写模块化代码以优化执行。

opcodecachingsimplovesphperforvesphpermance bycachingCompiledCode,reducingServerLoadAndResponSetimes.1)itstorescompiledphpcodeinmemory,bypassingparsingparsingparsingandcompiling.2)useopcachebachebachebachebachebachebachebysettingparametersinphametersinphp.ini,likeememeryconmorysmorysmeryplement.33)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

Atom编辑器mac版下载
最流行的的开源编辑器