http文件服务器(Ubuntu)

apache文件服务器(Ubuntu)

环境:Ubuntu18.4

需求:

搭建一个资源共享的文件下载站,支持多用户。

长这样:

在这里插入图片描述

传输文件的协议有很多,例如:http、ftp、smb、iSCSI等等,我们选择最简单的http协议。

一、安装

首先要获取root权限。

安装apache服务器

apt install apache2

关闭防火墙

ufw disable

访问该机ip即可看到测试页面

在这里插入图片描述

此时,apache安装完成。

二、配置

配置文件是 /etc/apache2/sites-enabled/000-default.conf

vi /etc/apache2/sites-enabled/000-default.conf

目前可能需要修改参数

参数说明
DocumentRoot需要提供下载的资源就存放在这个目录
<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

第一行的80即是访问端口。

默认就可以。将/var/www/html/index.html删除或更名。此时将文件放在DocumentRoot目录下,就可以实现效果。

在这里插入图片描述

三、多用户

配置

目前已经实现了一个共享的文件下载服务器,Linux是一个多用户的操作系统,现在为每一位用户都建一个私人的下载站。

进行简单的配置即可。

vi /etc/apache2/mods-available/userdir.conf

userdir.conf:

<IfModule mod_userdir.c>
	UserDir public_html
	UserDir disabled root

	<Directory /home/*/public_html>
		AllowOverride FileInfo AuthConfig Limit Indexes
		Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
		Require method GET POST OPTIONS
	</Directory>
</IfModule>

将此文件以及 /etc/apache2/mods-available/userdir.load 做个符号链接到 /etc/apache2/mods-enabled 目录下

ln -s ../mods-available/userdir.conf userdir.conf

ln -s ../mods-available/userdir.load userdir.load

创建用户

useradd -m httpdUser
# 添加用户并为用户创建登录目录
passwd httpUser
# 为用户设置密码
cd /home/httpUser

mkdir public_html

systemctl restart apache2
# 重启服务

现在,就可以通过 http://ip/~httpUser/ 来访问了

在这里插入图片描述

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!如果您想搭建一个 Ubuntu 文件服务器,下面是一些基本的步骤: 1. 安装 Ubuntu 操作系统:从 Ubuntu 官方网站下载并安装最新的稳定版 Ubuntu 操作系统。 2. 安装和配置 Samba:Samba 是一个开源软件套件,用于在 Linux 和 Windows 系统之间共享文件。您可以使用以下命令在 Ubuntu 上安装 Samba: ``` sudo apt update sudo apt install samba ``` 安装完成后,您需要编辑 Samba 配置文件以设置共享文件夹。可以通过编辑 `/etc/samba/smb.conf` 文件来进行配置。 3. 创建共享文件夹:选择一个目录作为您要共享的文件夹,并使用以下命令创建共享文件夹: ``` sudo mkdir /path/to/shared/folder ``` 4. 配置 Samba 共享:编辑 Samba 配置文件 `/etc/samba/smb.conf`,找到 `[global]` 部分并添加以下内容: ``` [shared] comment = Shared Folder path = /path/to/shared/folder browseable = yes read only = no guest ok = yes create mask = 0755 directory mask = 0755 ``` 这将创建一个名为 "shared" 的共享文件夹。 5. 创建 Samba 用户:为了访问 Samba 共享,您需要创建一个 Samba 用户。使用以下命令创建一个新的 Samba 用户并设置密码: ``` sudo smbpasswd -a username ``` 将 "username" 替换为您要创建的用户名。 6. 重启 Samba 服务:完成以上步骤后,使用以下命令重启 Samba 服务以使更改生效: ``` sudo service smbd restart ``` 现在,您应该能够从其他计算机上的 Windows 或 Linux 客户端访问您的 Ubuntu 文件服务器,并且可以通过共享文件夹传输和管理文件。请注意,如果您的服务器位于防火墙后面,您可能需要配置防火墙以允许 Samba 流量。 希望这些步骤对您有帮助!如有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值