如何限制对nginx上特定扩展的访问?

时间:2015-10-09 14:38:16

标签: regex linux nginx webserver

我想阻止通过NGINX直接访问我网站上的.phtml等扩展程序。所以我搜索并找到了一些解决方案,但没有一个能为我工作!

其中一些是: How to deny with 404 on nginx https://serverfault.com/questions/137907/how-to-restrict-access-to-directory-and-subdirs Replace NGINX 403 for deny with a different error response code

并且很遗憾没有(拒绝所有;并返回403;)工作。

这是我在nginx配置中的服务器部分:

    server {
    listen       *******:80;
    listen       127.0.0.1:80;
    #listen       [::1]:80;
    server_name  $hostname ******;

    root   /var/www/html;
    index  index.html index.htm index.php;

location ~ /\.phtml {
    return 403;
    deny all;
}       

# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
    try_files $uri =404;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    include /etc/nginx/fastcgi_params;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/usr/local/php55/sockets/webapps.sock;
}

    include /etc/nginx/nginx-info.conf;
    include /etc/nginx/webapps.conf;
}

所以请帮帮我,告诉我.phtml部分有什么问题!

非常感谢你

============================================ 编辑:

你好 我搜索了很多,我终于发现我使用的代码需要“ngx_http_access_module”并且它没有安装在我的系统上。我通过DirectAdmin CustomBuild 2安装了nginx,似乎没有安装该模块。

我尝试安装它,但我需要通过此代码安装该模块的预构建包:

"--add-module=/usr/local/directadmin/custombuild/custom/nginx/module-directory"

当我使用nginx包时,它返回

 configuring additional modules

在/usr/local/directadmin/custombuild/custom/nginx-1.8.0/src/http/modules/ngx_http_access_module.c中添加模块 ./configure:错误:没有找到/usr/local/directadmin/custombuild/custom/nginx-1.8.0/src/http/modules/ngx_http_access_module.c/config

请帮我安装该模块:)

0 个答案:

没有答案