nginx站点禁止目录执行php

作者: 健隆 分类: 服务器 发布时间: 2018-05-21 15:13

代码加入到server内,如下 :

location ~* ^/(uploads|templets)/.*.(php|php5)$ {
			deny all;
}

 完整站点配置如下:

server {
        listen       80;
        root /www/web/yujianlong_com/public_html;
        server_name yujianlong.com www.yujianlong.com;
        index  index.html index.php index.htm;
        fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
        error_page  400 /errpage/400.html;
        error_page  403 /errpage/403.html;
        error_page  404 /errpage/404.html;
        error_page  503 /errpage/503.html;
		location ~* ^/(uploads|templets)/.*.(php|php5)$ {
			deny all;
		}
        location ~ \.php(.*)$ {
                fastcgi_pass  unix:/tmp/php-55-cgi.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $DOCUMENT_ROOT$fastcgi_script_name;
                fastcgi_param PATH_INFO $2;
                include fcgi.conf;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
                expires      1d;
        }
        location ~ .*\.(js|css|html|htm)?$ {
                expires      12h;
        }
        location ~ /\.ht {
                deny  all;
        }
        location / {
                 try_files $uri $uri/ /?$args;
        }
}

 

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!