zoukankan      html  css  js  c++  java
  • Linux下安装nginx

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

    一、环境准备
    执行:

    [root@localhost hbk]# yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
    1
    2
    稍等片刻,见下面等完毕,说明准备好了依赖库。

    二、下载安装包
    准备好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
    1
    2
    3
    4
    5
    6
    四、配置,编译,安装
    配置

    [root@localhost nginx]# cd nginx-1.13.1
    [root@localhost nginx-1.13.1]# ./configure
    1
    2
    3
    编译,安装

    [root@localhost nginx-1.13.1]# make && make install
    1
    2
    这样安装没有指定安装路径,则默认安装在/usr/local/nginx目录,也可以指定安装目录,如:

    [root@localhost nginx-1.13.1]# ./configure --prefix=/root/hbk/nginx2/
    1
    2
    四、启动,运行
    进入到sbin目录

    [root@localhost nginx]# cd sbin/
    [root@localhost sbin]# ./nginx
    1
    2
    3
    停止命令为:

    [root@localhost sbin]# ./nginx -s stop
    1
    2
    重启命令为

    [root@localhost sbin]# ./nginx -s reload
    1
    2
    注意:在虚拟机上安装的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
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    直接在浏览器访问192.168.254.128,访问不了,执行service iptables stop也没用,后面在网友的帮助下解决该问题,原因是CentOS 7关闭防火墙的方式有所改变,执行

    systemctl stop firewalld
    1
    解决问题。


    ---------------------
    作者:黄宝康
    来源:CSDN
    原文:https://blog.csdn.net/huangbaokang/article/details/79917964
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    HDOJ 2577 How To Type
    HDOJ 1171 Big Event in HDU
    HDOJ 2159 FATE
    HDOJ 1176 免费馅饼
    POJ 1014 Dividing
    HDOJ 2844 Coins
    可以设置DefaultButton的TextBox控件
    setTimeout和setInterval的使用
    C# 调用ExchangeWebservice的相关代码
    实现IConfigurationSectionHandler接口来编写自定义配置
  • 原文地址:https://www.cnblogs.com/dingxiansheng/p/11077918.html
Copyright © 2011-2022 走看看