centos安装nginx----(6)

目标:在centos中安装nginx

1.下载nginx

我是在windows上下载好,然后上传到centos服务器上的
下载地址: http://nginx.org/en/download.html
我下载的版本是:nginx-1.14.2.tar.gz

2.解压nginx

[root@43-c59438365-0048-0727982 nginx]# pwd
/usr/java/nginx
[root@43-c59438365-0048-0727982 nginx]# ll
total 1000
drwxr-xr-x 9 1001 1001 4096 Jul 30 21:01 nginx-1.14.2
-rw-r--r-- 1 root root 1015384 Dec 4 2018 nginx-1.14.2.tar.gz
[root@43-c59438365-0048-0727982 nginx]#

3.安装nginx的依赖库

由于nginx中的gzip模块需要zlib库,rewrite模块需要pcre库,ssl功能需要openssl库。同时需要安装编译工具gcc。
我这里首先查看下我的系统是存在,不存在的再安装
采用如下命令查看是否安装过:rpm -qa|grep 库名

  • 查看gcc
    [root@43-c59438365-0048-0727982 nginx]# rpm -qa|grep gcc
    libgcc-4.8.5-16.el7.i686
    gcc-4.8.5-16.el7.x86_64
    libgcc-4.8.5-16.el7.x86_64
    [root@43-c59438365-0048-0727982 nginx]#
    我发现我的系统本身就安装了,这里就不再重复安装。
  • 安装pcre
    [root@43-c59438365-0048-0727982 nginx]# rpm -qa|grep pcre
    pcre-8.32-17.el7.i686
    [root@43-c59438365-0048-0727982 nginx]#
    发现安装有pcre,但是没有它的依赖包pcre-devel,因此我们采用yum安装下
    [root@43-c59438365-0048-0727982 nginx]# yum -y install pcre-devel
    安装好查看如下
    [root@43-c59438365-0048-0727982 nginx]# rpm -qa|grep pcre
    pcre-8.32-17.el7.i686
    pcre-8.32-17.el7.x86_64
    pcre-devel-8.32-17.el7.x86_64
    [root@43-c59438365-0048-0727982 nginx]#
  • 安装zlib
    [root@43-c59438365-0048-0727982 nginx]# rpm -qa|grep zlib
    zlib-1.2.7-18.el7.i686
    [root@43-c59438365-0048-0727982 nginx]#
    发现安装有zlib,但是没有它的依赖包zlib-devel,因此我们采用yum安装下
    [root@43-c59438365-0048-0727982 nginx]# yum -y install zlib-devel
    安装好后查看
    [root@43-c59438365-0048-0727982 nginx]# rpm -qa|grep zlib
    zlib-1.2.7-18.el7.x86_64
    zlib-devel-1.2.7-18.el7.x86_64
    zlib-1.2.7-18.el7.i686
    [root@43-c59438365-0048-0727982 nginx]#
  • 查看ssl
    [root@43-c59438365-0048-0727982 nginx]# rpm -qa|grep ssl
    mod_ssl-2.4.6-67.el7.centos.2.x86_64
    openssl-libs-1.0.2k-8.el7.x86_64
    python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch
    openssl-1.0.2k-8.el7.x86_64
    [root@43-c59438365-0048-0727982 nginx]#
    发现存在,就不再安装。

4.编译nginx

[root@43-c59438365-0048-0727982 nginx-1.14.2]# pwd
/usr/java/nginx/nginx-1.14.2
[root@43-c59438365-0048-0727982 nginx-1.14.2]# ll
total 768
drwxr-xr-x 6 1001 1001 4096 Jul 30 21:00 auto
-rw-r--r-- 1 1001 1001 288742 Dec 4 2018 CHANGES
-rw-r--r-- 1 1001 1001 440121 Dec 4 2018 CHANGES.ru
drwxr-xr-x 2 1001 1001 4096 Jul 30 21:00 conf
-rwxr-xr-x 1 1001 1001 2502 Dec 4 2018 configure
drwxr-xr-x 4 1001 1001 4096 Jul 30 21:00 contrib
drwxr-xr-x 2 1001 1001 4096 Jul 30 21:00 html
-rw-r--r-- 1 1001 1001 1397 Dec 4 2018 LICENSE
-rw-r--r-- 1 root root 376 Jul 30 21:06 Makefile
drwxr-xr-x 2 1001 1001 4096 Jul 30 21:00 man
drwxr-xr-x 3 root root 4096 Jul 30 21:07 objs
-rw-r--r-- 1 1001 1001 49 Dec 4 2018 README
drwxr-xr-x 9 1001 1001 4096 Jul 30 21:00 src
[root@43-c59438365-0048-0727982 nginx-1.14.2]# ./configure --prefix=/usr/java/nginx
[root@43-c59438365-0048-0727982 nginx-1.14.2]# make && make install

5.启动nginx

  • 方式1,注意路径,这不是解压nginx目录,而是安装目录
    [root@43-c59438365-0048-0727982 sbin]# pwd
    /usr/local/nginx/sbin
    [root@43-c59438365-0048-0727982 sbin]# ./nginx
  • 方式2,常用方式
    [root@43-c59438365-0048-0727982 nginx-1.14.2]# pwd
    /usr/java/nginx/nginx-1.14.2
    [root@43-c59438365-0048-0727982 nginx-1.14.2]# systemctl start nginx.service
    接着查看nginx启动状态
    [root@43-c59438365-0048-0727982 nginx-1.14.2]# systemctl status nginx.service
    或者采用 ps查看
    [root@43-c59438365-0048-0727982 nginx-1.14.2]# ps -aux|grep nginx
    root 5438 0.0 0.0 112664 972 pts/1 S+ 15:23 0:00 grep --color=auto nginx
    root 10915 0.0 0.0 20504 632 ? Ss Jul31 0:00 nginx: master process ./nginx
    nobody 10916 0.0 0.0 23048 1940 ? S Jul31 0:10 nginx: worker process

6.访问nginx

http://你的服务器ip:端口
就会出现nginx欢迎页面。

自此结束。

转载于:https://my.oschina.net/u/2312022/blog/3097052

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值