1.搭建文件服务器
server {
client_max_body_size 4G;
listen 80; ## listen for ipv4; this line is default and implied
server_name static.test.sdk.iwplay.com.tw;
root /home/mini/Sync;
location / {
}
}
2.建立索引
worker_processes 1;
events {
worker_connections 1024;
}
http {
sendfile on;
tcp_nodelay on;
keepalive_timeout 30;
server {
listen 80;
server_name localhost;
charset utf-8;
access_log logs/host.access.log;
root D:/Program/Apache-tomcat-6.0.41/webapps/test;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
}
4.设置密码
搭建文件服务器有时候不想让别人任意访问,想做成一个私有的该怎么办呢,这个时候我们可以用到nginx自带的认证模块。 同样关键的是auth_basic auth_basic_user_file字段
auth_basic表示的输入密码时的提示语
auth_basic_user_file则显示认证时的用户密码文件存放路径
server {
client_max_body_size 4G;
listen 80; ## listen for ipv4; this line is default and implied
server_name static.test.sdk.iwplay.com.tw;
root /home/mini/Sync;
location / {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/pass_file;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
}
5.生成用户密码
htpasswd -c -d /etc/nginx/pass_file yuansc
这样就在/etc/nginx/pass_file 中添加了了一个用户
这样我们一个简单的文件服务器就搭建完成了。