CentOS7搭建简单文件服务器

  • Post author:
  • Post category:其他


CentOS7使用nginx或httpd 搭建简单的文件服务器。



nginx 搭建

安装nginx

yum -y install nginx

修改配置文件,

vim  /etc/nginx/nginx.conf 

在access_log /var/log/nginx/access.log main;

一行后加上

autoindex on;# 显示目录
autoindex_exact_size on;# 显示文件大小
autoindex_localtime on;# 显示文件时间

如果想要修改默认的 端口号,修改server 中的两个listen 监听的端口号

修改完成 保存退出

nginx配置文件

清空 /usr/share/nginx/html 目录(该目录时nginx服务提供的网页端口访问对应的路径)

cd /usr/share/nginx/html
rm -rf *

将我们自己的文件放进去。可以直接创建两个测试一下

cd /usr/share/nginx/html
touch test
echo "白日依山尽" >> test
mkdir test-dir

启动nginx服务

systemctl enable nginx
systemctl start nginx

启动nginx

如果没有修改端口号,那默认的端口号是80。浏览器直接输入IP 即可访问(默认会访问80端口),如果修改了端口号 网页输入IP:PORT 即可访问

查看80端口占用

netstat -ntlp | grep 80

查看80端口占用

浏览器访问

文件服务器-nginx

修改默认路径 修改配置文件

vim /etc/nginx/nginx.conf

如修改为 /nginx

#root         /usr/share/nginx/html;
root         /nginx;



httpd 搭建

依然是先安装

yum -y install httpd

修改配置文件

vim /etc/httpd/conf/httpd.conf 

修改一下 监听端口号80 被占用,所以修改为8000

Listen 8000

然后启动,查看httpd 网络服务默认主页

systemctl enable httpd
systemctl start httpd

浏览器访问IP:8000

httpd默认主页

可以看有右边的提示 将 web 程序放在/var/www/html 在最终使用前屏蔽/etc/httpd/conf.d/welcome.conf

httpd的默认配置文件是/etc/httpd/conf/httpd.conf 这个算是附加配置。

设置 该文件

vim /etc/httpd/conf.d/welcome.conf
# 
# This configuration file enables the default "Welcome" page if there
# is no default index page present for the root URL.  To disable the
# Welcome page, comment out all the lines below. 
#
# NOTE: if this file is removed, it will be restored on upgrades.
#

大概就是 如果没有默认的初始页就会使用这个配置文件 指定的内容作为欢迎页。如果想要屏蔽掉欢迎页,就把所有行注释掉。。。如果删除了该文件,它会在升级恢复。

于是把所有内容屏蔽掉

httpd配置文件屏蔽

然后再默认的路径 /var/www/html/添加内容

cd /var/www/html/
touch test-httpd
echo "黄河入海流" >> test-httpd
mkdir testDIR-httpd
touch testDIR-httpd/gushi
echo "欲穷千里目,更上一层楼" >> testDIR-httpd/gushi

然后重启 httpd

systemctl restart httpd

浏览器访问 IP:8000

httpd文件服务器

emmm,httpd搭建文件服务器其实要设置的更多一点。。。这个只是基础设置,勉强能用。



版权声明:本文为dandanfengyun原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。