新开传奇网站发布网单职业,网页布局怎么设计,成都APP 微网站开发,用国外服务器做违法网站通过shell脚本分析部署nginx网络服务
1.接收用户部署的服务名称
[rootlocalhost xzy]# vim 1.sh
[rootlocalhost xzy]# chmod x 1.sh
[rootlocalhost xzy]# ./1.sh2.判断服务是否安装
已安装#xff1b;自定义网站配置路径为/www#xff1b;并创建共享目录和网页文件…通过shell脚本分析部署nginx网络服务
1.接收用户部署的服务名称
[rootlocalhost xzy]# vim 1.sh
[rootlocalhost xzy]# chmod x 1.sh
[rootlocalhost xzy]# ./1.sh2.判断服务是否安装
已安装自定义网站配置路径为/www并创建共享目录和网页文件重启服务
没有安装安装对应的软件包
#!/bin/bash# 1. 接收用户部署的服务名称
read -p 请输入您部署的服务名称: service_name
service_name$(echo $service_name | tr -d \b) # 去除退格键# 判断 Nginx 是否已安装
if command -v nginx /dev/null
thenecho Nginx 已经安装。# 2. 自定义网站配置echo 自定义网站配置路径为 /www。# 创建共享目录和网页文件sudo mkdir -p /www/htmlif [ $? -eq 0 ]; thenecho 共享目录 /www/html 创建成功。elseecho 创建共享目录 /www/html 失败请检查权限。exit 1fisudo echo htmlheadtitle$service_name/title/headbodyh1Welcome to $service_name/h1/body/html /www/html/index.htmlif [ $? -eq 0 ]; thenecho 网页文件 /www/html/index.html 创建成功。elseecho 创建网页文件 /www/html/index.html 失败请检查权限。exit 1fi# 确保配置目录存在if [ -d /etc/nginx/sites-available ]; thenecho 配置目录 /etc/nginx/sites-available 已存在。elsesudo mkdir -p /etc/nginx/sites-availableif [ $? -ne 0 ]; thenecho 创建配置目录 /etc/nginx/sites-available 失败请检查权限。exit 1fiecho 配置目录 /etc/nginx/sites-available 创建成功。fiif [ -d /etc/nginx/sites-enabled ]; thenecho 配置目录 /etc/nginx/sites-enabled 已存在。elsesudo mkdir -p /etc/nginx/sites-enabledif [ $? -ne 0 ]; thenecho 创建配置目录 /etc/nginx/sites-enabled 失败请检查权限。exit 1fiecho 配置目录 /etc/nginx/sites-enabled 创建成功。fi# 配置 Nginx 以使用自定义路径sudo tee /etc/nginx/sites-available/$service_name.conf EOF
server {listen 80;server_name localhost;location / {root /www/html;index index.html;}
}
EOFif [ $? -eq 0 ]; thenecho Nginx 配置文件 /etc/nginx/sites-available/$service_name.conf 创建成功。elseecho 创建 Nginx 配置文件 /etc/nginx/sites-available/$service_name.conf 失败请检查路径。exit 1fi# 创建符号链接使配置生效sudo ln -sf /etc/nginx/sites-available/$service_name.conf /etc/nginx/sites-enabled/if [ $? -eq 0 ]; thenecho 符号链接创建成功。elseecho 创建符号链接失败请检查路径。exit 1fi# 重启 Nginx 服务sudo systemctl restart nginx.serviceecho 已重启 Nginx 服务。# 3. 测试 Nginx 服务是否成功运行if sudo systemctl status nginx.service | grep -q active (running); thenecho Nginx 服务已成功启动。echo 可以通过浏览器访问地址 http://localhost 来查看您的网站。elseecho Nginx 服务没有成功启动。echo ----------- 配置文件内容如下 -----------sudo cat /etc/nginx/sites-available/$service_name.conffi
else# 2. 没有安装 Nginx安装对应的软件包echo Nginx 未安装开始安装 Nginx。sudo yum install nginx -y # 判断安装是否成功if command -v nginx /dev/nullthenecho Nginx 安装完成。# 创建共享目录和网页文件sudo mkdir -p /www/htmlif [ $? -eq 0 ]; thenecho 共享目录 /www/html 创建成功。elseecho 创建共享目录 /www/html 失败请检查权限。exit 1fisudo echo htmlheadtitle$service_name/title/headbodyh1Welcome to $service_name/h1/body/html /www/html/index.htmlif [ $? -eq 0 ]; thenecho 网页文件 /www/html/index.html 创建成功。elseecho 创建网页文件 /www/html/index.html 失败请检查权限。exit 1fi# 确保配置目录存在if [ -d /etc/nginx/sites-available ]; thenecho 配置目录 /etc/nginx/sites-available 已存在。elsesudo mkdir -p /etc/nginx/sites-availableif [ $? -ne 0 ]; thenecho 创建配置目录 /etc/nginx/sites-available 失败请检查权限。exit 1fiecho 配置目录 /etc/nginx/sites-available 创建成功。fiif [ -d /etc/nginx/sites-enabled ]; thenecho 配置目录 /etc/nginx/sites-enabled 已存在。elsesudo mkdir -p /etc/nginx/sites-enabledif [ $? -ne 0 ]; thenecho 创建配置目录 /etc/nginx/sites-enabled 失败请检查权限。exit 1fiecho 配置目录 /etc/nginx/sites-enabled 创建成功。fi# 自定义网站配置sudo tee /etc/nginx/sites-available/$service_name.conf EOF
server {listen 80;server_name localhost;location / {root /www/html;index index.html;}
}
EOFif [ $? -eq 0 ]; thenecho Nginx 配置文件 /etc/nginx/sites-available/$service_name.conf 创建成功。elseecho 创建 Nginx 配置文件 /etc/nginx/sites-available/$service_name.conf 失败请检查路径。exit 1fi# 创建符号链接使配置生效sudo ln -sf /etc/nginx/sites-available/$service_name.conf /etc/nginx/sites-enabled/if [ $? -eq 0 ]; thenecho 符号链接创建成功。elseecho 创建符号链接失败请检查路径。exit 1fi# 启动 Nginx 服务sudo systemctl start nginx.serviceecho 已启动 Nginx 服务。# 3. 测试 Nginx 服务是否成功运行if sudo systemctl status nginx.service | grep -q active (running); thenecho Nginx 服务已成功启动。echo 可以通过浏览器访问地址 http://localhost 来查看您的网站。elseecho Nginx 服务没有成功启动。echo ----------- 配置文件内容如下 -----------sudo cat /etc/nginx/sites-available/$service_name.conffielseecho Nginx 安装失败请检查您的网络连接和 YUM 源配置。fi
fi
3.测试
判断服务是否成功运行
已运行访问网站
未运行提示服务未启动并显示自定义的配置文件内容