Akemi

使用Apache搭建能够传输大文件的web文件服务器

2025/02/28
1
2
3
4
5
6
Alias "/downloads" "/var/www/files"
<Directory "/var/www/files">
Options Indexes FollowSymLinks
IndexOptions NameWidth=* FancyIndexing
Require all granted
</Directory>

Alias关键字

通过Alias将/var/www/files替换成了/downloads

这样我访问该目录时就可以直接访问http://IP/downloads/

而不是http://IP/files/

Alias的优势

  • 将物理目录与 URL 路径解耦,避免暴露服务器内部结构。
  • 可映射任意文件系统目录到 Web 路径,无需移动文件位置。
  • 通过 块精细控制权限,防止越权访问。

优化参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<IfModule mpm_event_module>
StartServers 3
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>

EnableSendfile On
EnableMMAP On
SendBufferSize 16384
ReceiveBufferSize 16384

Timeout 1800
KeepAlive On
KeepAliveTimeout 1800
MaxKeepAliveRequests 100

Alias "/downloads" "/var/www/files"
<Directory "/var/www/files">
Options +Indexes +FollowSymLinks
Require all granted
</Directory>

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType application/octet-stream "access plus 30 days"
</IfModule>

ServerTokens Prod
ServerSignature Off

不暴露文件目录结构(更安全)

1
2
3
4
5
6
7
8
9
10
11
12
Alias "/downloads" "/var/www/files"
<Directory "/var/www/files">
Options +Indexes +FollowSymLinks
Require all granted
</Directory>

改为
Alias "/downloads" "/var/www/files"
<Directory "/var/www/files">
Options -Indexes +FollowSymLinks
Require all granted
</Directory>

此时用户访问web界面会报错403 forbidden

但可以通过wget curl这种方式获取文件

wget http://192.168.10.102/downloads/2GB-testfile.bin

CATALOG
  1. 1. Alias关键字
  • 优化参数
  • 不暴露文件目录结构(更安全)