IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> http文件服务器(CentOS) -> 正文阅读

[系统运维]http文件服务器(CentOS)

apache文件服务器(CentOS)

环境:CentOS 8

需求:

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

长这样:

在这里插入图片描述

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

一、安装

先安装httpd

yum install httpd

关闭防火墙

systemctl disable firewalld
systemctl stop firewalld

启动httpd

systemctl start httpd

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

在这里插入图片描述

此时,httpd安装完成。

二、配置

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

vi /etc/httpd/conf/httpd.conf

目前可能需要修改参数

参数说明
DocumentRoot需要提供下载的资源就存放在这个目录
Linsten监听的端口

默认就可以。此时将文件放在DocumentRoot目录下,就可以实现效果。

在这里插入图片描述

问题1:无法访问到文件目录

此时可能会访问到刚才的测试页面或是403页面,原因是最后一行配置

IncludeOptional conf.d/*.conf

查看 conf.d 目录,该目录下有一个welcome.conf的文件

将这几行注掉即可:

#<LocationMatch "^/+$">
#    Options -Indexes
#    ErrorDocument 403 /.noindex.html
#</LocationMatch>

#<Directory /usr/share/httpd/noindex>
#    AllowOverride None
#    Require all granted
#</Directory>

配置完成记得重启服务

systemctl restart httpd

问题2:中文乱码

在配置文件结尾加入这样一行,全局配置编码,然后重启服务

IndexOptions Charset=UTF-8

问题3:文件名显示不全

全局配置name宽度自适应,然后重启服务

IndexOptions Charset=UTF-8 NameWidth=*

三、多用户

配置

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

进行简单的配置即可。

vi /etc/httpd/conf.d/userdir.conf

userdir.conf:

#
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.
#
# The path to the end user account 'public_html' directory must be
# accessible to the webserver userid.  This usually means that ~userid
# must have permissions of 711, ~userid/public_html must have permissions
# of 755, and documents contained therein must be world-readable.
# Otherwise, the client will only receive a "403 Forbidden" message.
#
<IfModule mod_userdir.c>
    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
    #UserDir disabled

    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, remove the "UserDir disabled" line above, and uncomment
    # the following line instead:
    # 
    UserDir public_html
</IfModule>

#
# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory "/home/*/public_html">
    AllowOverride FileInfo AuthConfig Limit Indexes
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS
</Directory>

根据提示,注释掉 UserDir disable 即可。

创建用户

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

mkdir public_html

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

更改权限

若是出现这个问题,则需要修改权限。

在这里插入图片描述

chmod 711 /home/httpUser

chmod 755 /home/httpUser/public_html

若仍然无效,那么有可能是受到SELinux的限制

chcon -R -t httpd_sys_content_t /home/*/public_html

成功

在这里插入图片描述

如果仍然无法正常访问,请查看错误日志:

cat /var/log/httpd/error_log
  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-10-31 12:39:36  更:2022-10-31 12:43:51 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年9日历 -2024/9/19 9:31:54-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码