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条)

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器