How to disable PHP execution permission for nginx Upload directories in lnmp

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.