之前已经出了Nginx搭建和配置的文章,所以不再赘述,如有不会搭建看下面链接:
下面直接开始使用Nginx搭建文件服务器
1、配置文件
#user nobody;
worker_processes 1;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# 显示目录
autoindex on;
# 显示文件大小
autoindex_exact_size on;
# 显示文件时间
autoindex_localtime on;
server {
listen 80;
server_name localhost;
# 本地文件路径
root D:\media\Picture;
}
}
主要是配置文件中的这一块:
# 显示目录
autoindex on;
# 显示文件大小
autoindex_exact_size on;
# 显示文件时间
autoindex_localtime on;
server {
listen 80;
server_name localhost;
# 本地文件路径
root D:\picture;
}
2、启动Nginx
点击图片链接:http://localhost/test.jpg