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

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能