使用nginx搭建简易的文件共享服务器

网友投稿 380 2022-11-06


使用nginx搭建简易的文件共享服务器

前期准备

使用yum的方法安装nginx,提供以下脚本供安装使用。

#!/bin/bash. /etc/os-release#捕获ctrl+c信号trap "exit" INT #日志处理color(){ if [[ "$1" == "error" ]] then printf "\e[1;31m[Error] $(date +"%F %T"): $2\n\e[0m" elif [[ "$1" == "info" ]] then printf "\e[1;32m[info] $(date +"%F %T"): $2\n\e[0m" elif [[ "$1" == "warning" ]] then printf "\e[1;33m[warning] $(date +"%F %T"): $2\n\e[0m" fi}#安装nginx,目前在rocky8,ubnutu20.4运行无问题,其他版本未试过_install_nginx(){ REPLY=y color warning "reinstall will uninstall and install again,deep think about...." [[ -f "/lib/systemd/system/nginx.service" ]] && read -p "your already installed nginx,do you want install again[y|n]?" case $REPLY in y|Y) if [[ "$ID" == "ubuntu" ]] then color info "uninstall nginx" sudo apt autoremove nginx -y color info "install nginx" #ubuntu sudo apt update -y curl | gpg --dearmor \ | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ `lsb_release -cs` nginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list sudo apt update sudo apt install nginx -y systemctl restart nginx systemctl status nginx curl -I 127.0.0.1:80|grep "HTTP/1.1 200 OK" &>/dev/null color info "nginx server is running ...." elif [[ "$ID" == "rocky" ]] then color info "uninstall nginx" yum install yum-utils expect -y yum autoremove nginx -y color info "install nginx" [ -f "/etc/yum.repos.d/nginx.repo" ] && mv /etc/yum.repos.d/nginx.repo /etc/yum.repos.d/nginx.repo.bak.$(date +%s) &>/dev/null cat >/etc/yum.repos.d/nginx.repo</dev/null color info "nginx server is running ...." fi ;; n|N) exit 0 ;;*) echo "input error,exit after 2 second" sleep 2 exit 1esac}

新建目录

mkdir -p /myrepo/epel #路径可随意

关闭selinux

如果不关闭会出现403的报错,关闭完成后重启机器生效

sed '/^SELINUX=/ s/enforcing/disabled/' -i /etc/selinux/config

临时关闭

[root@localhost yum.repos.d]# setenforce 0[root@localhost yum.repos.d]# getenforce Permissive

​​将安装脚本保存为.sh文件,然后使用bash 脚本名.sh​​执行脚本

修改nginx配置文件,添加如下配置

location /repo { alias /myrepo/epel; autoindex on; }

重启nginx

systemctl restart nginx

访问http://ip/repo,出现如下界面说明配置成功


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:聊聊注解@Aspect的AOP实现操作
下一篇:大数据查询API(大数据查询个人轨迹)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~