编译安装nginx脚本(在线离线都适用)
#!/bin/bash #******************************************************************** #Author: HE-handsome #QQ: 2700565402 #Date: 2022-09-30 #FileName: install_nginx.sh #email: hpneed977@outlook.com #Description:路漫漫其修远兮,吾将上下而求索 #******************************************************************** . /etc/os-release version=1.20.2 install () { if [ -e nginx-${version}.tar.gz ];then echo "文件存在,安装进行中。。。" else echo "开始下载源码文件。。。" wget http://nginx.org/download/nginx-${version}.tar.gz [ $? -eq 0 ] || { echo "下载失败!立即退出!";exit; } fi if id nginx &> /dev/null;then echo "用户存在" else groupadd -g 990 -r nginx && useradd -g nginx -s /sbin/nologin -r -u 990 nginx echo "创建nginx用户" fi echo "安装依赖包" if [ $ID == "rocky" -o $ID == "centos" ];then yum -y install make gcc 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 tar xf nginx-${version}.tar.gz -C /usr/local/src cd /usr/local/src/nginx-${version} ./configure --prefix=/apps/nginx \ --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 && make install [ $? -eq 0 ] && echo "nginx-configure success" || { echo "nginx-configure faile";exit; } chown -R nginx.nginx /apps/nginx ln -s /apps/nginx/sbin/nginx /usr/sbin/ cat > /lib/systemd/system/nginx.service << EOF [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking #PIDFile=/apps/nginx/run/nginx.pid ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf ExecReload=/bin/kill -s HUP \$MAINPID ExecStop=/bin/kill -s TERM \$MAINPID LimitNOFILE=100000 [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable --now nginx &> /dev/null [ $? -eq 0 ] && echo "nginx-start success" || { echo "nginx-start faile";exit; } } install
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律