aiweek-reconstruction/createfileserver.sh

43 lines
1.0 KiB
Bash
Raw Normal View History

2024-05-20 01:00:09 +08:00
#!/usr/bin/bash
CONFIG_FILE="/etc/nginx/nginx.conf"
CONFIG_BLOCK=$(cat <<EOF
autoindex on; # 显示目录
autoindex_exact_size on; # 显示文件大小
autoindex_localtime on; # 显示文件时间
server {
listen 233 default_server;
listen [::]:233 default_server;
server_name _;
root /data/;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
EOF
)
yum -y install nginx
if [ ! -f "$CONFIG_FILE" ]; then
echo "配置文件不存在: $CONFIG_FILE"
exit 1
fi
sed -i 's/^user nginx;/user root;/' "$CONFIG_FILE"
if [ $? -eq 0 ]; then
echo "用户配置文件已更新。"
else
echo "更新用户配置文件失败。"
fi
sed -i '/^http\s*{/,/^}/a '"$CONFIG_BLOCK" "$NGINX_CONFIG"
if [ $? -eq 0 ]; then
echo "fileserver配置文件已更新。"
else
echo "更新fileserver配置文件失败。"
fi
nginx -s reload