平时安装软件都是用yum安装,简单粗暴。今天要说的是Nginx的编译安装。

  1. 安装软件依赖包(pcre-devel,openssl-devel)
    pcre-devel:语言正则表达式兼容软件包
    openssl-devel:使系统支持https方式访问
    [root@NFS ~]# yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel
  2. 创建一个管理nginx进程的虚拟用户
    [root@NFS ~]# useradd www -s /sbin/nologin/ -M
  3. 下载并解压nginx软件
    [root@NFS usr]# cd /application/tools/
    [root@NFS tools]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
    --2019-11-26 15:30:20--  http://nginx.org/download/nginx-1.12.2.tar.gz
    Resolving nginx.org... 62.210.92.35, 95.211.80.227, 2001:1af8:4060:a004:21::e3
    Connecting to nginx.org|62.210.92.35|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 981687 (959K) [application/octet-stream]
    Saving to: “nginx-1.12.2.tar.gz”
    
    100%[===========================================================================================================>] 981,687     86.8K/s   in 7.0s    
    
    2019-11-26 15:30:32 (136 KB/s) - “nginx-1.12.2.tar.gz” saved [981687/981687]
    [root@NFS tools]#
    [root@NFS tools]# tar xf nginx-1.12.2.tar.gz 
    [root@NFS tools]# ll
    total 200624
    -rw-r--r-- 1 root root  10291220 Nov 26 11:41 apache-tomcat-8.5.49.tar.gz
    -rw-r--r-- 1 root root 194151339 Nov 26 11:44 jdk-8u231-linux-x64.tar.gz
    drwxr-xr-x 8 1001 1001      4096 Oct 17  2017 nginx-1.12.2
    -rw-r--r-- 1 root root    981687 Oct 17  2017 nginx-1.12.2.tar.gz
    [root@NFS tools]# 
    
  4. 进行软件编译安装
    ①. 编译配置(通过./configure --help 查看nginx所有参数)
    [root@NFS tools]# cd /application/toos/nginx-1.12.2
    [root@NFS nginx-1.12.2]# ./configure --prefix=/application/nginx-12.2 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
    
    [root@NFS nginx-1.12.2]# echo $?   #通过该命令判断上一步骤是否成功0表示成功,非0失败
    0
    [root@NFS nginx-1.12.2]# 
    --prefix=PATH     指定软件安装在什么目录下
    --user=USER       指定软件worker进程管理用户,利用www虚拟用户管理worker进程
    --group=USER    指定用户组
    --with-http_ssl_module           使nginx程序可以支持HTTPsF访问功能
    --with-http_stub_status_module     用于监控用户访问nginx服务情况

    ②. 编译安装
    [root@NFS nginx-1.12.2]# make && make install
    去/application/下查看nginx(因为指定安装到该目录下)
    [root@NFS nginx-1.12.2]# cd /application/
    [root@NFS application]# ll
    total 32
    drwxr-xr-x 9 root root 4096 Nov 23 19:07 apache-tomcat-8.5.49
    lrwxrwxrwx 1 root root   26 Nov 23 18:38 jdk -> /application/jdk1.8.0_231/
    drwxr-xr-x 7 root root 4096 Oct  5 18:13 jdk1.8.0_231
    drwxr-xr-x 6 root root 4096 Nov 26 16:57 nginx-12.2
    drwxr-xr-x 5 root root 4096 Nov 25 22:02 projects
    -rw-r--r-- 1 root root  179 Nov 23 18:46 test.txt
    lrwxrwxrwx 1 root root   34 Nov 23 19:08 tomcat -> /application/apache-tomcat-8.5.49/
    drwxr-xr-x 9 root root 4096 Nov 23 19:07 tomcat1
    drwxr-xr-x 9 root root 4096 Nov 23 19:07 tomcat2
    drwxr-xr-x 3 root root 4096 Nov 26 15:31 tools
    [root@NFS application]# 

     

  5. 为nginx程序软件创建链接目录
    [root@NFS application]# ln -s /application/nginx-12.2 /application/nginx
    [root@NFS application]# ll
    total 32
    drwxr-xr-x 9 root root 4096 Nov 23 19:07 apache-tomcat-8.5.49
    lrwxrwxrwx 1 root root   26 Nov 23 18:38 jdk -> /application/jdk1.8.0_231/
    drwxr-xr-x 7 root root 4096 Oct  5 18:13 jdk1.8.0_231
    lrwxrwxrwx 1 root root   23 Nov 26 16:58 nginx -> /application/nginx-12.2
    drwxr-xr-x 6 root root 4096 Nov 26 16:57 nginx-12.2
    drwxr-xr-x 5 root root 4096 Nov 25 22:02 projects
    -rw-r--r-- 1 root root  179 Nov 23 18:46 test.txt
    lrwxrwxrwx 1 root root   34 Nov 23 19:08 tomcat -> /application/apache-tomcat-8.5.49/
    drwxr-xr-x 9 root root 4096 Nov 23 19:07 tomcat1
    drwxr-xr-x 9 root root 4096 Nov 23 19:07 tomcat2
    drwxr-xr-x 3 root root 4096 Nov 26 15:31 tools
    [root@NFS application]# 

     
  6. 启动nginx程序服务
    [root@NFS application]# nginx/sbin/nginx 
    [root@NFS application]# ps -ef|grep nginx
    root      12800      1  0 17:01 ?        00:00:00 nginx: master process nginx/sbin/nginx
    www       12801  12800  0 17:01 ?        00:00:00 nginx: worker process
    root      12809   9892  0 17:03 pts/0    00:00:00 grep --color=auto nginx
    [root@NFS application]# 
    master process nginx/sbin/nginx 是Nginx的主进程,管理Nginx的服务
    worker process  是Nginx的工作进程,处理用户访问请求(可以再nginx/nginx.conf中进行配置数量)

    nginx/sbin/nginx                          #启动Nginx服务
    nginx/sbin/nginx -t                      #检查nginx配置文件语法格式是否正确
    nginx/sbin/nginx -s reload          #平滑重启Nginx服务
    nginx/sbin/nginx -s stop             #停止Nginx服务
    nginx/sbin/nginx -V                 #查看当前nginx配置参数
    nginx/sbin/nginx -h                     #nginx命令说明
    [root@NFS nginx]# sbin/nginx -h
    nginx version: nginx/1.12.2
    Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
    
    Options:
      -?,-h         : this help
      -v            : show version and exit
      -V            : show version and configure options then exit
      -t            : test configuration and exit
      -T            : test configuration, dump it and exit
      -q            : suppress non-error messages during configuration testing
      -s signal     : send signal to a master process: stop, quit, reopen, reload
      -p prefix     : set prefix path (default: /application/nginx-12.2/)
      -c filename   : set configuration file (default: conf/nginx.conf)
      -g directives : set global directives out of configuration file


     

  7. 去浏览器访问 10.0.0.31:80

     

Nginx安装就搞定了,是不是也不难吧,接下来我们还要对它的程序目录结构了解一下。

[root@NFS application]# cd nginx
[root@NFS nginx]# ll
total 36
drwx------ 2 www  root 4096 Nov 26 17:01 client_body_temp
drwxr-xr-x 2 root root 4096 Nov 26 16:57 conf
drwx------ 2 www  root 4096 Nov 26 17:01 fastcgi_temp
drwxr-xr-x 2 root root 4096 Nov 26 16:57 html
drwxr-xr-x 2 root root 4096 Nov 26 17:01 logs
drwx------ 2 www  root 4096 Nov 26 17:01 proxy_temp
drwxr-xr-x 2 root root 4096 Nov 26 16:57 sbin
drwx------ 2 www  root 4096 Nov 26 17:01 scgi_temp
drwx------ 2 www  root 4096 Nov 26 17:01 uwsgi_temp

conf          --- nginx程序所有配置文件保存目录
                    nginx.conf   nginx程序主配置文件

html          --- nginx程序站点目录

logs           --- nginx程序日志文件保存目录

sbin           --- nginx程序命令所在目录

最后修改于 2019-11-29 10:08:43
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付
上一篇