Nginx开启服务器文件目录访问

By timebusker on August 26, 2018
  • nginx.conf
user  root;
worker_processes  4;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    gzip  on;
    include /etc/nginx/conf.d/*.conf;
}
  • default.conf
server {
    listen       80;
    server_name  www.timebusker.com;
    charset utf8;
    #access_log  /var/log/nginx/log/host.access.log  main;

    # URL路径要与根目录下的路径匹配才能访问
    location /ambari/ {
	    root /root/ambari/
        autoindex on;                   //开启目录浏览功能;   
        autoindex_exact_size off;       //关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b;   
        autoindex_localtime on;         //开启以服务器本地时区显示文件修改日期! 
    }
    error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}