Nginx配置只开放指定目录访问

 

server {
        listen       80;
        server_name  www.test.com ;  #域名
        root   "/path/to/webroot/"; #项目所在路径
   location / {
         #规则重写
         if (!-e $request_filename) {
            rewrite  ^/index.php(.*)$  /index.php?s=$1  last;
            rewrite  ^(.*)$  /index.php?s=$1  last;
            break;
         }
         #开放uploads目录
         location /uploads/ {
            break;
         }
         #开放favicon.ico图片文件, 该图片为显示在浏览tab栏上的网站logo
         location ~ ^/favicon.ico$ {
            break;
         }
         #只输入域名也能访问到默认的index.php,不至于被显示404
         location ~ ^/$ {
            break;
         }
         #访问以上情况之外的文件都显示404
         return 404;
    }
    #添加下列信息,配置Nginx通过fastcgi方式处理您的PHP请求
    location ~ ^/index\.php$ {
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      fastcgi_param  PHP_VALUE        open_basedir=$document_root:/tmp/:/proc/;
      include        fastcgi_params;
    }
}

你可能感兴趣的:(nginx)