bugweixin 2017-04-04 19:13 采纳率: 50%
浏览 1830
已采纳

nginx 下禁止目录解析php

    location ~* ^/(attachments|upload)/.*\.(php|php5)?$ {
       deny all;
    }
            我想禁止 upload 这个目录以及他的下级目录禁止执行php

            upload 目录在 www/user/upload

            这是我的nginx 配置
网上所说的其他正则我也试过,重启了都不行。

我用的lnmp安装的。

那位大神说一下 如何配置

 user  www www;

worker_processes auto;

error_log  /home/wwwlogs/nginx_error.log  crit;

pid        /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
    {
        use epoll;
        worker_connections 51200;
        multi_accept on;
    }

        include       mime.types;
        default_type  application/octet-stream;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile   on;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        #limit_conn_zone $binary_remote_addr zone=perip:10m;
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

        server_tokens off;
        access_log off;

server
    {
        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;
        server_name default;
        index index.html index.htm index.php;
        root  /home/wwwroot/default;

        #error_page   404   /404.html;
         include enable-php.conf;


        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location /
        {
            if (-f $request_filename/index.html){
                rewrite (.*) $1/index.html break;
                }
            if (-f $request_filename/index.php){
                rewrite (.*) $1/index.php;
                }
            if (!-f $request_filename){
                rewrite (.*) /index.php;
                }
        }
        location ~/\.
        {
            deny all;
        }

        location ~* ^/(attachments|upload)/.*\.(php|php5)?$ {
           deny all;
        }
        location ~ .*\.(php|php5)?$
        {
           fastcgi_pass unix:/tmp/php-cgi.sock;
           fastcgi_index index.php;
           include fastcgi.conf;
        }


        access_log  /home/wwwlogs/access.log;

    }

include vhost/*.conf;
}
  • 写回答

2条回答 默认 最新

  • bugweixin 2017-04-05 05:27
    关注

    跪求大神解决一下,谢谢

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Error in check.length("fill") : 'gpar'成分'fill'的长度不能为零
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导