rocky8编译安装nginx

官方链接

nginx newshttp://nginx.org/选择版本

这里我选择安装1.20.2版本

[root@rocky8 ~]#wget http://nginx.org/download/nginx-1.20.2.tar.gz
[root@rocky8 ~]#tar xf nginx-1.20.2.tar.gz

安装依赖编译的软件

[root@rocky8 ~]#yum -y install gcc pcre-devel openssl-devel zlib-devel

创建用户

[root@rocky8 ~]#useradd -s /sbin/nologin nginx

./config

[root@rocky8 ~]#cd /root/nginx-1.20.2
[root@rocky8 nginx-1.20.2]#./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

[root@rocky8 nginx-1.20.2]#make -j 2 && make install
#一般编译报错需要安装以下软件
yum -y install gcc automake autoconf libtool make

修改权限

[root@rocky8 nginx-1.20.2]#chown nginx.nginx /apps/nginx

启动服务

[root@rocky8 ~]#/apps/nginx/sbin/nginx
[root@rocky8 ~]#ss -ntl
State     Recv-Q    Send-Q       Local Address:Port         Peer Address:Port    Process
LISTEN    0         128                0.0.0.0:80                0.0.0.0:*
LISTEN    0         128                0.0.0.0:22                0.0.0.0:*
LISTEN    0         128                   [::]:22

用service文件启动

#创建service文件需要修改配置文件
[root@rocky8 ~]# mkdir /apps/nginx/run
[root@rocky8 ~]#vim /apps/nginx/conf/nginx.conf
pid        /apps/nginx/run/nginx.pid;
[root@rocky8 ~]#vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/apps/nginx/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /apps/nginx/run/nginx.pid
ExecStartPre=/apps/nginx/sbin/nginx -t
ExecStart=/apps/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=mixed
PrivateTmp=true

[Install]
WantedBy=multi-user.target
[root@rocky8 ~]#systemctl daemon-reload
[root@rocky8 ~]#systemctl enable --now nginx
[root@rocky8 ~]#ss -ntl
State         Recv-Q         Send-Q                 Local Address:Port                 Peer Address:Port        Process
LISTEN        0              128                          0.0.0.0:80                        0.0.0.0:*
LISTEN        0              128                          0.0.0.0:22                        0.0.0.0:*
LISTEN        0              128                             [::]:22                           [::]:*

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhu1241jie

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值