Prohibit the website or attachment directory from running PHP scripts in Apache or Nginx

Source: Internet
Author: User
Tags php file


If the uploaded directory is embedded with a PHP file, the file can be executed remotely. For the sake of security, PHP scripts cannot be run on the upload directory.

In Apache, we can use the following method to disable the running of PHP scripts:

<Directory/wp-content/uploads>
Php_flag engine off
</Directory>

The Nginx method is as follows:

Location/wp-content/uploads /{
Location ~ . * \. (Php )? $ {
Deny all;
 } 

For multiple directories, you can restrict them together:

Location ~ * ^/(Uploads | images)/. * \. (php | php5) $

Deny all;


Lighthttpd

$ HTTP ["url"] = ~ "^/(Forumdata | templates | upload | images )/"{
Fastcgi. server = ()
}

For example, the WordPress attachment directory does not allow PHP to run.

I am using nginx. Here is how to disable it:

Location/wp-content/uploads /{
Location ~ . * \. (Php )? $ {
Deny all;
    }
}

Insert your nginx conf file and restart nginx.
The following is an example of a complete VM:

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/wp-content/uploads /{
Location ~ . * \. (Php )? $ {
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.