nginx站点目录及文件URL访问控制

一、根据扩展名限制程序和文件访问

利用nginx配置禁止访问上传资源目录下的PHP、Shell、Perl、Python程序文件。

配置nginx,禁止解析指定目录下的指定程序。

location ~ ^/images/.*\.(php|php5|sh|pl|py)$
		{
			deny all;
		}
		
location ~ ^/static/.*\.(php|php5|sh|pl|py)$
		{
			deny all;
		}
		
location ~ ^/data/(attachment|avatar).*\.(php|php5)$
		{
			deny all;
		}

 对上述目录的限制必须卸载nginx处理PHP服务配置的前面,如下:

放置在server标签内:

    server {
        listen       80;
        server_name  www.dmtest.com;
        location / {
            root   html;
            index  index.php index.html index.htm;
        }

        location ~ ^/images/.*\.(php|php5|sh|pl|py)$
            {
                deny all;
            }

        location ~ ^/static/.*\.(php|php5|sh|pl|py)$
            {
                deny all;
            }

        location ~ ^/data/(attachment|avatar).*\.(php|php5)$
            {
                deny all;
            }
		
		......
		......
	}

猜你喜欢

转载自www.cnblogs.com/Mr-Ding/p/9575670.html
今日推荐