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个回答

跪求大神解决一下,谢谢

检查下 include vhost/*.conf; ,从你这个配置上www/user/upload这个目录无法在浏览器访问到的

weixin_38185378
bugweixin 回复Gauss_sz: 我弄好了,是location 路径 然后里面写条件
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐