nginx1.10.2编译安装

该文章详细描述了在CentOS系统中安装Nginx的过程,包括下载安装包,设置仓库,解压并创建用户和日志目录,安装依赖,编译配置,以及启动Nginx服务。同时,文章也展示了如何检查Nginx是否成功监听端口。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.下载安装包

//安装网络仓库
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
[root@localhost yum.repos.d]# yum clean all && yum makecache
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ls
nginx-1.10.2.tar.gz

2.解压、创建用户、日志目录

[root@localhost src]# tar xf nginx-1.10.2.tar.gz -C /usr/local/
[root@localhost src]# tar xf nginx-1.10.2.tar.gz -C /usr/local/
[root@localhost src]# useradd -r -M -s /sbin/nologin nginx
[root@localhost src]# mkdir -p /var/log/nginx
[root@localhost src]# chown -R nginx.nginx /var/log/nginx

3. 下载依赖包、编译安装

[root@localhost ~]# cd /usr/local/nginx-1.10.2/
[root@localhost nginx-1.10.2]# yum -y install  gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
[root@localhost nginx-1.10.2]# ./configure \
--prefix=/usr/local/nginx/ \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_sub_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log
[root@localhost nginx-1.10.2]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install

4. 启动nginx

//创建环境变量
[root@localhost nginx-1.10.2]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost nginx-1.10.2]# source /etc/profile.d/nginx.sh 
[root@localhost nginx-1.10.2]# nginx 

//查看端口号
[root@localhost nginx-1.10.2]# ss -antl
State       Recv-Q Send-Q        Local Address:Port                       Peer Address:Port              
LISTEN      0      128                       *:111                                   *:*                  
LISTEN      0      128                       *:80                                    *:*                  
LISTEN      0      128                       *:22                                    *:*                  
LISTEN      0      100               127.0.0.1:25                                    *:*                  
LISTEN      0      128                    [::]:111                                [::]:*                  
LISTEN      0      128                    [::]:22                                 [::]:*                  
LISTEN      0      100                   [::1]:25                                 [::]:*                  
LISTEN      0      70                     [::]:33060                              [::]:*                  
LISTEN      0      128                    [::]:3306                               [::]:*                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

彭宇栋

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

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

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

打赏作者

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

抵扣说明:

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

余额充值