下载Nginx for Windows
解压Nginx
C:\nginx
)C:\nginx\conf\nginx.conf
http
块内添加或修改server配置:server {
listen 80;
server_name localhost;
# 文件服务器根目录配置
location / {
root D:/file_server; # 修改为你的文件目录路径
autoindex on; # 开启目录列表功能
autoindex_exact_size off; # 显示文件大小(KB/MB)
autoindex_localtime on; # 显示本地时间
}
# 防止显示隐藏文件
location ~ /\. {
deny all;
}
}
file_server
文件夹(或你指定的其他路径)启动方法
cd C:\nginx
start nginx
验证运行
http://localhost
start nginx
nginx -s stop
nginx -s quit
nginx -s reload
nginx -s reopen
auth_basic "Restricted Area";
auth_basic_user_file conf/htpasswd;
allow 192.168.1.0/24;
deny all;
index index.html index.htm;
方法一:使用任务计划程序
C:\nginx\nginx.exe
方法二:创建服务(需要第三方工具如NSSM)
nssm install nginx
防火墙设置
权限问题
性能优化
worker_connections
和keepalive_timeout
参数安全问题
通过以上步骤,您可以在Windows 10系统上成功配置Nginx作为文件服务器。根据实际需求,您可以进一步调整配置参数。