Linux下安装nginx

nginx依赖gcc,pcre等库。安装nginx之前需要在linux下加入nginx所依赖的库。

一、环境准备

执行:

[root@localhost hbk]# yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

稍等片刻,见下面等完毕,说明准备好了依赖库。

这里写图片描述

二、下载安装包

准备好nginx安装包,别问我要,我也是官网下载的。

这里写图片描述

我是在window下载的,不过你也可以通过在linux下使用wget下载。使用各种办法(ftp等)把安装包放到/root/hbk/nginx目录下,前提条件下提前新建了相应文件夹。

三、解压

解压:

[root@localhost nginx]# pwd
/root/hbk/nginx
[root@localhost nginx]# ls
nginx-1.13.1.tar.gz
[root@localhost nginx]# tar -zxvf nginx-1.13.1.tar.gz 

四、配置,编译,安装

配置

[root@localhost nginx]# cd nginx-1.13.1
[root@localhost nginx-1.13.1]# ./configure 

编译,安装

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

这样安装没有指定安装路径,则默认安装在/usr/local/nginx目录,也可以指定安装目录,如:

[root@localhost nginx-1.13.1]# ./configure --prefix=/root/hbk/nginx2/

四、启动,运行

进入到sbin目录

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

停止命令为:

[root@localhost sbin]# ./nginx -s stop

重启命令为

[root@localhost sbin]# ./nginx -s reload

注意:在虚拟机上安装的nginx,启动完nginx在本机浏览器访问可能由于防火墙的原因,访问不了。

[root@localhost sbin]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.254.128  netmask 255.255.255.0  broadcast 192.168.254.255
        inet6 fe80::f963:84bd:83f7:170f  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:19:88:40  txqueuelen 1000  (Ethernet)
        RX packets 51549  bytes 61893281 (59.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14950  bytes 1369925 (1.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 64  bytes 5568 (5.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 64  bytes 5568 (5.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost sbin]# ps -ef|grep nginx
root       3850      1  0 17:48 ?        00:00:00 nginx: master process ./nginx
nobody     3851   3850  0 17:48 ?        00:00:00 nginx: worker process
root       3873   1151  0 17:58 pts/0    00:00:00 grep --color=auto nginx

直接在浏览器访问192.168.254.128,访问不了,执行service iptables stop也没用,后面在网友的帮助下解决该问题,原因是CentOS 7关闭防火墙的方式有所改变,执行

systemctl  stop  firewalld

解决问题。

这里写图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

黄宝康

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

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

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

打赏作者

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

抵扣说明:

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

余额充值