Nginx从入门到实战(二):Linux安装Nginx

前序:Nginx从入门到实战(一):介绍

Linux安装Nginx

注意: docker安装更便捷,这里介绍原生安装。

1.安装依赖包

​ 所需依赖有:pcre zlib zlib-devel gcc-c++ libtool openssl openssl-devel

​ 如果安装比较慢的话,可以切换镜像源,切换方式见如下文章https://blog.csdn.net/wdy_2099/article/details/70578529

安装命令如下:

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

2.安装Nginx

​ 下载nginx-1.12.2.tar.gz包(下载地址 http://nginx.org/download/)可以根据实际情况下载其他版本。

2.1 首先解压:

[root@localhost nginx]# tar -xvf nginx-1.12.2.tar.gz 

2.2 解压后,进入目录nginx-1.12.2,然后执行./configure 执行检查操作
开启stream块

 ./configure --with-stream 
[root@localhost nginx]# cd nginx-1.12.2/
[root@localhost nginx-1.12.2]# ./configure 

补充:如果需要支持https模块,则需要执行如下命令:

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

2.3 最后执行编译

[root@localhost nginx-1.12.2]# make && make install

2.4 编译以后会在/usr/local下生成nginx文件夹,sbin下有启动脚本

/usr/local/nginx/sbin

[root@localhost nginx]# cd sbin/
[root@localhost sbin]# ls
nginx

3.启动Nginx

启动sbin下的nginx

[root@localhost sbin]# ./nginx
[root@localhost sbin]# 

访问默认80端口:(我这边服务器地址为http://192.168.1.117:80/),出现以下界面则为启动成功:

在这里插入图片描述

注意:CentoS7中操作防火墙的规则外部访问需要开放对应端口

查看开放的端口号 
firewall-cmd --list-all 
设置开放的端口号 
firewall-cmd --add-service=http --permanent 
firewall-cmd --add-port=80/tcp --permanent 
重启防火墙 
firewall-cmd --reload 
  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

一掬净土

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

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

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

打赏作者

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

抵扣说明:

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

余额充值