CentOS7源代码编译安装Nginx

2 篇文章 0 订阅

1.准备环境:

系统版本:Centos7.9

准备软件:

Nginx版本:nginx-1.23.3

1.1 下载阿里云网络yum源和epel扩展源

[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
[root@localhost ~]# yum makeche && yum clean all

2 编译安装Nginx

2.1 安装nginx依赖包
[root@localhost ~]# yum -y install GeoIP-devel.x86_64 gd-devel.x86_64  libxslt-devel gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* 
2.2 创建nginx用户
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
2.3 下载nginx源码包并解压
[root@localhost ~]# yum -y install wget
[root@localhost ~]# wget https://nginx.org/download/nginx-1.23.3.tar.gz
[root@localhost ~]# tar zxvf nginx-1.23.3.tar.gz -C /usr/src
                                  -C  指定解压目录
[root@localhost ~]# cd /usr/src/nginx-1.23.3
[root@localhost nginx-1.23.1]#
./configure \
    --with-threads \
    --with-file-aio \
    --with-http_ssl_module \
    --with-http_v2_module \
    --with-http_realip_module \
    --with-http_addition_module \
    --with-http_xslt_module=dynamic \
    --with-http_image_filter_module=dynamic \
    --with-http_geoip_module=dynamic \
    --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_auth_request_module \
    --with-http_random_index_module \
    --with-http_secure_link_module \
    --with-http_degradation_module \
    --with-http_slice_module \
    --with-http_stub_status_module \
    --with-stream=dynamic \
    --with-stream_ssl_module \
    --with-stream_realip_module \
    --with-stream_geoip_module=dynamic \
    --with-stream_ssl_preread_module \
    --with-compat  \
    --with-pcre-jit && make -j4 && make install

编写nginx系统启动脚本

[root@localhost ~]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
  
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target

2.4 启动nginx服务 并将nginx网站端口加入防火墙规则

[root@localhost ~]# systemctl enable nginx --now
[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
[root@localhost ~]# firewall-cmd --zone=public --add-port=443/tcp --permanent
[root@localhost ~]# firewall-cmd --reload

2.5 查看nginx是否启动

[root@localhost ~]# netstat -anptu | grep 80

2.6 访问nginx默认网页

用浏览器访问 192.168.43.254(访问你的服务器ip地址)

当看到这个页面就说明Nginx安装成功了

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

笨鸟先飞geigeigei

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

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

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

打赏作者

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

抵扣说明:

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

余额充值