linux搭建简单的http文件服务

51 阅读1分钟

写在前面

内容是抄的,安装的时候,看了一些网文,良莠不齐,花费了一些时间,记录下。
原文请看:www.cnblogs.com/zhuyeshen/p…

烦恼

  • 想要通过wget下载文件/给别人提供文件
  • 想要在浏览器点点点看linux目录

搭建

下载
Ubuntu 中通过apt-get install apache2 安装 apache2
CentOS 中通过yum install httpd 安装 httpd

配置
apache2 配置文件是/etc/apache2/apache2.conf
httpd 配置文件是/etc/httpd/conf/httpd.conf

可选配置

  • 修改端口: Listen 8888
  • :(尽量使用默认配置,哪天需要重新部署到新机器上,都不维护配置,哈哈,就是懒。

启动
service httpd start
:(restart、stop,重启、停止

目录设置
服务器默认的访问路径在/var/www/html目录下,需要对外提供的,使用软连接方式,例如:sudo ln -s /home/work/var/ /var/www/html

效果
浏览器可以直接打开:http://hostname:port/var/,方便。

image.png

使用技巧

下载文件
wget http://hostname:port/var/123.dat

下载目录
wget -r -np -nH --cut-dirs=1 --reject='index.html*' http://hostname:port/var/test_dir/

参数:

  • -r:递归下载。
  • -np:不追溯到上级目录。
  • -nH:不创建主机目录。
  • --cut-dirs=1:去掉 URL 中的前一级目录,也就是 http://hostname:port/
  • --reject="index.html*":过滤掉 index.html 开头的文件。

注意:链接最后一定要有『/』,也就是test_dir后面跟的『/』,即『.../test_dir/』
:(否则,会把test_dir同级目录的所有东西都下载,hahah