news 2026/6/15 0:54:03

nginx安装部署

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
nginx安装部署

执行如下脚本即可编译安装指定版本

#!/bin/bash SRC_DIR=/usr/local/src NGINX_URL=http://nginx.org/download/ NGINX_FILE=nginx-1.29.4 TAR=.tar.gz NGINX_INSTALL_DIR=/apps/nginx CPUS=`lscpu |awk '/^CPU\(s\)/{print $2}'` . /etc/os-release color () { RES_COL=60 MOVE_TO_COL="echo -en \\033[${RES_COL}G" SETCOLOR_SUCCESS="echo -en \\033[1;32m" SETCOLOR_FAILURE="echo -en \\033[1;31m" SETCOLOR_WARNING="echo -en \\033[1;33m" SETCOLOR_NORMAL="echo -en \E[0m" echo -n "$1" && $MOVE_TO_COL echo -n "[" if [ $2 = "success" -o $2 = "0" ] ;then ${SETCOLOR_SUCCESS} echo -n $" OK " elif [ $2 = "failure" -o $2 = "1" ] ;then ${SETCOLOR_FAILURE} echo -n $"FAILED" else ${SETCOLOR_WARNING} echo -n $"WARNING" fi ${SETCOLOR_NORMAL} echo -n "]" echo } os_type () { awk -F'[ "]' '/^NAME/{print $2}' /etc/os-release } os_version () { awk -F'"' '/^VERSION_ID/{print $2}' /etc/os-release } check () { [ -e ${NGINX_INSTALL_DIR} ] && { color "nginx 已安装,请卸载后再安装" 1; exit; } cd ${SRC_DIR} if [ -e ${NGINX_FILE}${TAR} ];then color "相关文件已准备好" 0 else color '开始下载 nginx 源码包' 0 wget ${NGINX_URL}${NGINX_FILE}${TAR} [ $? -ne 0 ] && { color "下载 ${NGINX_FILE}${TAR}文件失败" 1; exit; } fi } install () { color "开始安装 nginx" 0 if id nginx &> /dev/null;then color "nginx 用户已存在" 1 else useradd -s /sbin/nologin -r nginx color "创建 nginx 用户" 0 fi color "开始安装 nginx 依赖包" 0 if [ $ID == "centos" ] ;then if [[ $VERSION_ID =~ ^7 ]];then yum -y -q install make gcc pcre-devel openssl-devel zlib-devel perl-ExtUtils-Embed elif [[ $VERSION_ID =~ ^8 ]];then yum -y -q install make gcc-c++ libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel perl-ExtUtils-Embed else color '不支持此系统!' 1 exit fi elif [ $ID == "rocky" ];then yum -y -q install make gcc-c++ libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel perl-ExtUtils-Embed else apt update &> /dev/null apt -y install make gcc libpcre3 libpcre3-dev openssl libssl-dev zlib1g-dev &> /dev/null fi cd $SRC_DIR tar xf ${NGINX_FILE}${TAR} NGINX_DIR=`echo ${NGINX_FILE}${TAR}| sed -nr 's/^(.*[0-9]).*/\1/p'` cd ${NGINX_DIR} ./configure --prefix=${NGINX_INSTALL_DIR} --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module make -j $CPUS && make install [ $? -eq 0 ] && color "nginx 编译安装成功" 0 || { color "nginx 编译安装失败,退出!" 1 ;exit; } echo "PATH=${NGINX_INSTALL_DIR}/sbin:${PATH}" > /etc/profile.d/nginx.sh cat > /lib/systemd/system/nginx.service <<EOF [Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=${NGINX_INSTALL_DIR}/logs/nginx.pid ExecStartPre=/bin/rm -f ${NGINX_INSTALL_DIR}/logs/nginx.pid ExecStartPre=${NGINX_INSTALL_DIR}/sbin/nginx -t ExecStart=${NGINX_INSTALL_DIR}/sbin/nginx ExecReload=/bin/kill -s HUP \$MAINPID KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process PrivateTmp=true LimitNOFILE=100000 [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable --now nginx &> /dev/null systemctl is-active nginx &> /dev/null || { color "nginx 启动失败,退出!" 1 ; exit; } color "nginx 安装完成" 0 } check install
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/15 11:20:15

‌AI公平性验证:测试数据集构建指南‌

一、公平性数据集的战略价值 在贷款审批AI中&#xff0c;不同邮政编码申请人的通过率差异可达40%&#xff1b;医疗诊断模型对深肤色患者的误诊率高出白种人15%。这些触目惊心的数据揭示&#xff1a;数据集质量直接决定AI系统的伦理底线。对测试工程师而言&#xff0c;构建无偏…

作者头像 李华
网站建设 2026/6/15 14:55:54

12306 购票辅助工具:余票监控提醒 + 候补自动提交(支持 Windows)

每到节假日或热门时段&#xff0c;12306 官方放票时间不固定&#xff0c;热门车次往往很快售罄&#xff0c;很多用户需要反复刷新页面&#xff0c;依然难以成功购票。 本文整理一款适用于 Windows 系统的 12306 购票辅助工具&#xff0c;通过 余票监控、候补提醒、自动填写购票…

作者头像 李华
网站建设 2026/6/15 9:01:13

奇技淫巧之花里胡哨的VIM---插件的添加与美化

奇技淫巧之花里胡哨的VIM—插件的添加与美化 一、前期准备工作 1.VIM版本要为9.0以上&#xff0c;自行检查&#xff0c;如果不是的话&#xff0c;使用PPA安装 sudo add-apt-repository ppa:jonathonf/vim sudo apt update#Ubuntu发行版会自动更新&#xff0c;不需要手动 sudo…

作者头像 李华
网站建设 2026/6/15 12:15:52

Flutter for OpenHarmony二手物品置换App实战 - 聊天对话实现

聊天功能是买卖双方沟通的核心&#xff0c;买家询问商品细节、协商价格、约定交易方式都在聊天中完成。今天我们来实现"闲置换"的聊天页面&#xff0c;包括消息气泡展示和消息发送功能。 聊天页面的设计思路 聊天页面的核心是消息列表和输入框。消息列表展示双方的…

作者头像 李华
网站建设 2026/6/15 11:20:24

基于python的社区生鲜团购系统vue3

文章目录社区生鲜团购系统技术摘要--nodejs技术栈--结论源码文档获取/同行可拿货,招校园代理 &#xff1a;文章底部获取博主联系方式&#xff01;社区生鲜团购系统技术摘要 技术栈组合 采用Python作为后端开发语言&#xff0c;搭配Vue3作为前端框架。后端通常使用Django或Flas…

作者头像 李华