centos7 编译安装nginx1.16.0( 完整版 )

一、安装依赖包

yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

依赖包说明:

1、编译依赖 gcc 环境,所以需要:gcc gcc-c++;

2、PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库,所以需要:pcre pcre-devel ;

3、zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库,所以需要:zlib zlib-devel ;

4、OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库,所以需要:openssl openssl-devel

二、从官网下载安装包

wget https://nginx.org/download/nginx-1.16.0.tar.gz

三、解压并安装

tar zxvf nginx-1.16.0.tar.gz

cd nginx-1.16.0

./configure --prefix=/usr/local/nginx

make && make install

四、测试安装是否成功

[root@localhost ~]# nginx -V
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
configure arguments: --prefix=/usr/local/nginx

五、启动nginx服务

cd /usr/local/nginx/sbin

./nginx

六、验证服务是否启动成功

[root@localhost sbin]# netstat -ntlp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      349/nginx: master 

七、添加nginx服务

vi /lib/systemd/system/nginx.service

将以下内容插入:

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

八、以服务的方式启动nginx

pkill nginx
systemctl start nginx

九、查看服务是否启动

[root@localhost sbin]# systemctl status nginx
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-04-29 23:19:39 EDT; 18min ago
  Process: 348 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 349 (nginx)
    Tasks: 2
   Memory: 976.0K
   CGroup: /system.slice/nginx.service
           ├─349 nginx: master process /usr/local/nginx/sbin/nginx
           └─350 nginx: worker process

Apr 29 23:19:39 localhost.localdomain systemd[1]: Starting nginx...
Apr 29 23:19:39 localhost.localdomain systemd[1]: Started nginx.

[root@localhost sbin]# netstat -ntlp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      349/nginx: master p 

十、配置nginx服务自动启动

[root@localhost sbin]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.


centos7 nginx1.16.0 反向代理 编译安装

yum -y install gcc-c++
yum -y install pcre pcre-devel
yum -y install openssl openssl-devel
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --user=nginx --with-http_ssl_module --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/client/ --http-proxy-temp-path=/usr/local/nginx/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/fcgi/ --with-pcre --add-module=/usr/local/fastdfs-nginx-module-1.20/src/

make && make install
useradd nginx
#测试
/usr/local/nginx/sbin/nginx -v
/usr/local/nginx/sbin/nginx
netstat -ntlp |grep 80

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值