centos安装nginx----(6)

目标:在centos中安装nginxhtml

1.下载nginx

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

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]#python

3.安装nginx的依赖库

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

  • 查看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 installwindows

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欢迎页面。centos

自此结束。服务器

相关文章
相关标签/搜索