We recommend that you remove the PHP permission for the website directory. When you access the PHP file under the upload Directory, error 403 is returned. The following describes in detail how to remove the PHP execution permission of the specified directory in the lnmp environment.
First, edit the nginx virtual host configuration. Add the following content before the location statement of fastcgi:
1. Remove PHP execution permission from a single directory
| The code is as follows: |
Copy code |
Location ~ /Attachments/. *. (php | php5 )? $ {
Deny all;
}
|
Remove the PHP execution permission in the attachments directory.
2. Remove PHP execution permission from multiple directories
| The code is as follows: |
Copy code |
Location ~ /(Attachments | upload)/. *. (php | php5 )? $ {
Deny all;
}
|
Remove the PHP execution permissions of the attachments and upload directories.
The following is an example of a complete VM:
| The code is as follows: |
Copy code |
|
Server
{
Listen 80;
Server_name bbs.vpser.net;
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;
Fcinclude GI. conf;
}
Access_log off;
} |
Run the following command to test the configuration file:/usr/local/nginx/sbin/nginx-t: /usr/local/nginx/sbin/nginx-s reload load the configuration file to make it take effect