上上海网站建设设计,网站 缓存方式,多用户商城系统价格,网站建设要钞钱搭建简单文件服务器 基于centos7.9搭建http文件服务器基于centos7.9搭建nginx文件服务器基于ubuntu2204搭建http文件服务器 IP环境192.168.200.100VMware17
基于centos7.9搭建http文件服务器
安装httpd
[rootlocalhost ~]# yum install -y httpd关闭防火墙以及selinux
[roo… 搭建简单文件服务器 基于centos7.9搭建http文件服务器基于centos7.9搭建nginx文件服务器基于ubuntu2204搭建http文件服务器 IP环境192.168.200.100VMware17
基于centos7.9搭建http文件服务器
安装httpd
[rootlocalhost ~]# yum install -y httpd关闭防火墙以及selinux
[rootlocalhost ~]# systemctl stop firewalld;setenforce 0文件/etc/httpd/conf/httpd.conf中的默认参数自定义修改
DocumentRoot /var/www/html #这一行指定了文档根目录Directory /var/www #用于针对指定目录在这里是/var/www设置访问控制规则的开始标签。以下的配置将应用于/var/www目录及其子目录。AllowOverride None# Allow open access:Require all granted #表示允许所有人访问/var/www目录及其子目录没有访问限制
/DirectoryListen 80 #默认的监听端口修改80后则需要指定IP:端口进行访问注释/etc/httpd/conf.d/welcome.conf文件下的此内容不然就会返回禁止访问报错
#LocationMatch ^/$
# Options -Indexes
# ErrorDocument 403 /.noindex.html
#/LocationMatch文件服务器下创建测试文件
[rootlocalhost ~]# echo hello /var/www/html/test.txt启动httpd并设置开机自启
[rootlocalhost ~]# systemctl enable --now httpd访问界面如下 此时的文件服务器还不能下载点击后会打开该文件 编辑http.conf文件追加以下内容
FilesMatch \.(?i:pdf|zip|txt|csv)$Header set Content-Disposition attachment
/FilesMatch当有人请求以 .pdf、.zip、.txt 或 .csv 结尾的文件时服务器会设置 Content-Disposition 标头强制
将文件作为附件下载而不是在浏览器中直接打开如果还要添加例如tar、gz等文件后缀可以下载
则需要在括号内添加(?i:pdf|zip|txt|csv|gz|tar)相应的后缀[rootlocalhost ~]# systemctl restart httpd此时重新打开无痕模式浏览器或者清除缓存再次打开 完善文件服务器的浏览器界面在http.conf的Directory标签中添加 Options Indexes启用目录索引允许显示目录内容。 IndexOptions FancyIndexing启用美化的目录索引以改善目录内容的可读性。 IndexOptions NameWidth允许文件名列宽度自动调整以适应不同文件名的长度。 IndexOptions DescriptionWidth允许描述列宽度自动调整以适应不同文件描述的长度。 IndexOptions FoldersFirst将文件夹显示在文件之前以提高目录索引的可读性。 Directory /var/wwwAllowOverride None# Allow open access:Require all granted #以下为添加内容Options IndexesIndexOptions FancyIndexing NameWidth* DescriptionWidth* FoldersFirst
/Directory[rootlocalhost ~]# systemctl restart httpd基于centos7.9搭建nginx文件服务器
安装wget命令需要拉取阿里源的epel源再下载nginx
[rootlocalhost ~]# yum install -y wget
[rootlocalhost ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
[rootlocalhost ~]# yum install -y nginx
[rootlocalhost ~]# yum info nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile* base: mirrors.cqu.edu.cn* extras: mirrors.cqu.edu.cn* updates: mirrors.cqu.edu.cn
Installed Packages
Name : nginx
Arch : x86_64
Epoch : 1
Version : 1.20.1
Release : 10.el7
Size : 1.7 M
Repo : installed
From repo : epel
Summary : A high performance web server and reverse proxy server
URL : https://nginx.org
License : BSD
Description : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and: IMAP protocols, with a strong focus on high concurrency, performance and low: memory usage.修改nginx.conf文件
[rootlocalhost ~]# vi /etc/nginx/nginx.conf
user nginx; #nginx改为root#在server配置标签上添加以下内容autoindex on;# 显示目录autoindex_exact_size on;# 显示文件大小autoindex_localtime on;# 显示文件时间root /opt; #/opt表示你要共享的文件服务器根目录启动nginx并开机自启
[rootlocalhost ~]# systemctl enable --now nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.浏览器IP访问如果要指定端口修改Linsten后面的80即可 基于ubuntu2204搭建http文件服务器
IP环境192.168.200.200VMware17
安装apache2
roothuhy:~# apt install -y apache2roothuhy:~# mkdir /var/www/html/test-file
roothuhy:~# chmod 777 /var/www/html/test-file/
roothuhy:~# echo ok /var/www/html/test-file/test.txt
roothuhy:~# vi /etc/apache2/sites-available/000-default.confDocumentRoot /var/www/html/test-file #修改此参数就可以指向该文件夹
roothuhy:~# systemctl enable --now apache2
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable apache2浏览器IP访问 优化界面
roothuhy:~# vi /etc/apache2/apache2.confDirectory /var/www/ #对此目录下生效Options Indexes FollowSymLinksAllowOverride NoneRequire all granted #添加下面两行Options IndexesIndexOptions FancyIndexing NameWidth* DescriptionWidth* FoldersFirst
/Directory再次访问 总的来说ubuntu搭建更加简单一些做的配置也不多