nginx.conf中配置如下内容

##在linux命令下执行/datadir先建好目录 
mkdir /datadir

##在nginx.conf中加入
vi /etc/nginx/nginx.conf 

server {

    listen       8080 default_server;
    listen       [::]:8080 default_server;
    server_name  localhost;

		location / {
		    root /datadir;  //指定哪个目录作为Http文件服务器的根目录
		    autoindex on;   //设置允许列出整个目录
		    autoindex_exact_size off; //默认为on,显示出文件的确切大小,单位是bytes。改为off后,显示出文件的大概大小,单位是kB或者MB或者GB
		    autoindex_localtime on; //默认为off,显示的文件时间为GMT时间。改为on后,显示的文件时间为文件的服务器时间
		    charset utf-8; //防止文件乱码显示, 如果用utf-8还是乱码,就改成gbk试试
		}

}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.

关闭selinux

sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config && setenforce 0
  • 1.

重启nginx

sudo systemctl restart nginx.service

curl http://localhost:8080
  • 1.
  • 2.
  • 3.