编译安装nginx--1.16

脚本思路可能有点复杂,有什么问题可以留言,我会改进的

#!/usr/bin/bash
#编译安装nginx,个人使用,不能用于生产,用于生产概不负责
#刘彬彬
#有事联系此邮箱liubinbin0215@163.com

echo "此脚本用于一键编译安装nginx仅限个人使用,不想安装请在10秒内,Ctrl+c停止"
sleep 10
wt() {
`wget -P /usr/local/src/ -nc  http://nginx.org/download/nginx-1.16.0.tar.gz` #可以修改软件包版本,下面解压(109行)进入也要修改
}
#编译配置,需要什么添加什么,这里所有的配置已经指定目录
configure(){
cd /usr/local/src/nginx-1.16.0     
./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_image_filter_module \
--with-http_slice_module \
--with-mail \
--with-threads \
--with-file-aio \
--with-stream \
--with-mail_ssl_module \
--with-stream_ssl_module 
}

systemctl disable firewalld 
if [[ $? -ne 0 ]];then
        echo "关闭失败"
        exit
else
        echo "防火墙已经关闭"
fi

get={ getenforce 0 }
if [[ $get = Disabled || $get = permissive ]];then
        echo "关闭失败"
        exit
else
        echo "selinux已经关闭"
fi

ping -c1  www.baidu.com 
if [[ $? -ne 0 ]];then
        echo "网络不通,请手动检查网络"
	exit
else
        echo "网络通畅,可以安装软件"
fi

yum -y install gcc gcc-c++  
if [[ $? -ne 0 ]];then
	echo "编译环境安装失败"
	exit
else
	echo "编译环境安装成功"
fi
yum install -y pcre pcre-devel 
#使nginx支持http rewrite模块
if [[ $? -ne 0 ]];then
        echo "安装失败"
	exit
else
        echo "安装pcre成功"
fi

yum install -y openssl openssl-devel 
#使nginx支持ssl
if [[ $? -ne 0 ]];then
        echo "安装失败"
        exit
else    
        echo "安装openssl-devel成功"
fi

yum install -y zlib zlib-devel gd gd-devel 
if [[ $? -ne 0 ]];then
        echo "安装失败"
        exit
else
        echo "安装zlib成功"
fi
useradd -s /sbin/nologin nginx
#使创建的nginx用户没有登录的权限,为了安全
if [[ $? -ne 0 ]];then
        echo "创建用户失败"
        break
else
        echo "创建用户成功"
fi

wt 
#上面定义的函数,写起来太长不宜读,下载nginx-1.16包
if [[ $? -ne 0 ]];then
        echo "下载失败,有可能已经存在安装包"

else    
        echo "下载成功"
fi

cd /usr/local/src/
#解压
tar -zxvf nginx-1.16.0.tar.gz 

echo "配置文件,指定目录,如果不想指定目录请Ctrl+c退出脚本"
sleep 5
configure   &>/etc/null   #上面有函数,在开头
if [[ $? -ne 0 ]];then
        echo "配置失败"
        exit
else
        echo "配置成功"
fi

echo "开始安装"
sleep 3
make &>/dev/null && make install
if [[ $? -ne 0 ]];then
        echo "安装失败"
        exit
else
        echo "安装成功"
fi

echo "启动服务"
sleep 3
cd /usr/local/nginx/sbin
./nginx 
netstat -ntlp | grep nginx 
if [[ $? -ne 0 ]];then
        echo "启动失败"
        exit
else
       echo "nginx启动成功,可以使用了"
fi
cd /usr/local/nginx/sbin
./nginx -s stop

#把nginx添加system管理
cat >/usr/lib/systemd/system/nginx.service  <<EOF
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s QUIT \$MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF
echo "添加权限,执行权"
chmod +x /usr/lib/systemd/system/nginx.service

echo "开机自启配置中"
#实验一下这几项是否可以正常使用
systemctl daemon-reload 
systemctl start nginx.service
systemctl stop nginx.service 
systemctl reload nginx.service
systemctl restart nginx.service
systemctl enable nginx.service
if [[ $? -ne 0 ]];then
        echo "启动失败"
        exit
else
        echo "启动成功"
fi

nginx-quic是nginx的一个版本,它支持QUIC协议。QUIC是一种基于UDP的传输协议,旨在提供更快的连接建立和数据传输速度。要获取nginx-quic版本的nginx可执行文件,需要进行一系列的安装编译步骤。 首先,你可以使用已经编译好的版本nginx-quic.linux-x86_64.zip,下载链接在\[5\]中提供。如果你想自己编译,可以按照以下步骤进行准备工作: 1. 下载nginx源码包:使用curl命令下载nginx源码包,例如: ``` curl -O https://nginx.org/download/nginx-1.16.1.tar.gz ``` 2. 解压源码包:使用tar命令解压下载的源码包,例如: ``` tar xvzf nginx-1.16.1.tar.gz ``` 3. 克隆quiche库:使用git命令克隆quiche库,例如: ``` git clone --recursive https://github.com/cloudflare/quiche ``` 4. 进入nginx源码目录:使用cd命令进入nginx源码目录,例如: ``` cd nginx-1.16.1 ``` 5. 应用补丁:使用patch命令应用quiche提供的补丁,例如: ``` patch -p01 < ../quiche/extras/nginx/nginx-1.16.patch ``` 6. 配置编译选项:使用./configure命令配置编译选项,例如: ``` ./configure \ --prefix=$PWD \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_v3_module \ --with-openssl=../quiche/deps/boringssl \ --with-quiche=../quiche ``` 7. 编译安装:使用make命令编译安装nginx,例如: ``` make && make install ``` 完成以上步骤后,你就可以得到nginx-quic版本的nginx可执行文件。请注意,这些步骤可能会遇到一些问题,你可以参考\[2\]和\[3\]提供的链接获取更详细的信息和指导。 #### 引用[.reference_title] - *1* [如何在 Nginx 中启用 HTTP 3.0/QUIC 支持](https://blog.csdn.net/easylife206/article/details/112975714)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Nginx支持quic协议](https://blog.csdn.net/liucy007/article/details/129383417)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Nginx官方nginx-quic搭建](https://blog.csdn.net/qq_37177958/article/details/120444034)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值