First, edit the virtual host configuration of nginx and add the following content in front of the location statement of fastcgi:
1. Remove PHP execution permission from a single directory
Location ~ /attachments/.*.(php|php5)?$ {
deny all;
}
Remove PHP execution permissions from the attachments directory.
2. Remove PHP execution permissions from multiple directories
Location ~ /(attachments|upload)/.*.(php|php5)?$ {
deny all;
}
Remove PHP execution permissions from the attachments and upload directories.
Attached is a complete virtual host example for reference:
server
{
Listen 80;
server_name www.45it.com;
index index.html index.htm index.php;
root /home/wwwroot/bbs.vpser.net;include discuz.conf;
Location ~ /(attachments|upload)/.*.(php|php5)?$ {
deny all;
}
Location ~ .*.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
access_log off;
}
After adding, execute: /usr/local/nginx/sbin/nginx -t to test the configuration file, execute: /usr/local/nginx/sbin/nginx -s reload to load the configuration file to make it effective.
Note: Pay attention to the order and must be placed above the line "location ~ .*.(php|php5)?$", otherwise it will not take effect.