php防止上传木马被运行设置

目的是能上传的目录不能运行PHP,能运行PHP的目录没有上传权限。
建立新的只读用户nginxr,并加到webgrp组
useradd -r -s /sbin/nologin nginxr
usermod -a -G webgrp nginxr
程序目录
chown nginxr:webgrp -R 程序目录
find ./ -type d -exec chmod 755 {} \;
find ./ -type f -exec chmod 640 {} \;
静态文件目录,设置为只读
chown nginx:webgrp -R static/
find ./static -type d -exec chmod 550 {} \;
find ./static -type f -exec chmod 550 {} \;
可写目录
chown nginx:webgrp -R 可写目录
find ./runtime -type d -exec chmod 750 {} \;
find ./runtime -type f -exec chmod 600 {} \;
find ./test_write -type d -exec chmod 750 {} \;
find ./test_write -type f -exec chmod 600 {} \;
nginx配置文件
location ~ [^/]\.php(/|$) {
# 这里是加入的代码,屏蔽一些不能运行php的目录
    if ($request_uri ~* ‘/test_write|/runtime|/static’) {
        return 403;
    }
    # 屏蔽结束
    include         fastcgi.conf;
    fastcgi_index   index.php;
    fastcgi_pass    php73_fpm;
}