nginx安装脚本

复制代码
 1 #!/bin/bash
 2 version=nginx-1.20.1.tar.gz
 3 name=nginx-1.20.1
 4 install_dir=/usr/local
 5 log=/var/log/nginx
 6 #解决依赖关系
 7 yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel wget gd-devel gcc gcc-c++
 8 yum -y groups mark install 'Development Tools'
 9 #创建用户
10 id nginx &>/dev/null
11 if [ $? -ne 0 ];then
12 useradd -s /sbin/nologin nginx
13 fi
14 #创建日志存放目录
15 if [ ! -d $log ];then
16 mkdir -p /var/log/nginx
17 chown -R nginx.nginx /var/log/nginx
18 fi
19 #下载nginx
20 cd /usr/src/
21 wget http://nginx.org/download/$version
22 #解压
23 tar xf $version
24 mv $name nginx
25 cd nginx/ && ./configure \
26 --prefix=$install_dir/nginx \
27 --user=nginx \
28 --group=nginx \
29 --with-debug \
30 --with-http_ssl_module \
31 --with-http_realip_module \
32 --with-http_image_filter_module \
33 --with-http_gunzip_module \
34 --with-http_gzip_static_module \
35 --with-http_stub_status_module \
36 --http-log-path=$log/access.log \
37 --error-log-path=$log/error.log
38  
39 make && make install
40 #配置环境变量
41 echo "export PATH=$install_dir/nginx/sbin:\$PATH" > /etc/profile.d/nginx.sh
42 source /etc/profile.d/nginx.sh
43  
44 #创建服务文件
45 cat > /usr/lib/systemd/system/nginx.service <
46  
47 [Unit]
48 Description=nginx
49 After=network.target
50  
51 [Service]
52 Type=forking
53 ExecStart=$install_dir/nginx/sbin/nginx
54 ExecReload=$install_dir/nginx/sbin/nginx -s reload
55 ExecStop=$install_dir/nginx/sbin/nginx -s quit
56 PrivateTmp= true
57  
58 [Install]
59 WantedBy=multi-user.target
60  
61 EOF
62 #开机自启
63 systemctl enable --now nginx
复制代码

 

posted @   leiuk  阅读(74)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
点击右上角即可分享
微信分享提示