发布于 

Nginx安装步骤记录

记录linux下两种Nginx的安装方式和步骤。

若可以使用Root用户安装Nginx,则

1
2
3
sudo yum install nginx-1.18.0-1.el7.ngx.x86_64.rpm
sudo systemctl status nginx
sudo systemctl start nginx

配置完成后使用如下命令检查配置是否正确

1
nginx -t

若无问题,使用如下命令加载配置

1
nginx -s reload

若不能使用Root用户安装Nginx,则

  1. 使用root用户安装依赖

    1
    2
    3
    yum -y install gcc-c++ 
    yum -y install pcre-devel
    yum -y install zlib-devel
  2. 创建用户zjkapp,切换到zjkapp用户,创建目录/home/zjkapp/soft

  3. 将文件nginx-1.18.0.tar.gz上传到/home/zjkapp/soft

  4. 解压

    1
    2
    cd /home/zjkapp/soft
    tar -zxvf nginx-1.18.0.tar.gz
  5. 检查、编译安装

    1
    2
    cd /home/zjkapp/soft/nginx-1.18.0
    ./configure --prefix=/home/zjkapp/soft/nginx --with-http_stub_status_module

    成功的检查结果如下所示:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    Configuration summary
    + using system PCRE library
    + OpenSSL library is not used
    + using system zlib library

    nginx path prefix: "/home/zjkapp/soft/nginx"
    nginx binary file: "/home/zjkapp/soft/nginx/sbin/nginx"
    nginx modules path: "/home/zjkapp/soft/nginx/modules"
    nginx configuration prefix: "/home/zjkapp/soft/nginx/conf"
    nginx configuration file: "/home/zjkapp/soft/nginx/conf/nginx.conf"
    nginx pid file: "/home/zjkapp/soft/nginx/logs/nginx.pid"
    nginx error log file: "/home/zjkapp/soft/nginx/logs/error.log"
    nginx http access log file: "/home/zjkapp/soft/nginx/logs/access.log"
    nginx http client request body temporary files: "client_body_temp"
    nginx http proxy temporary files: "proxy_temp"
    nginx http fastcgi temporary files: "fastcgi_temp"
    nginx http uwsgi temporary files: "uwsgi_temp"
    nginx http scgi temporary files: "scgi_temp

    编译安装

    1
    make && make install
  6. 进入nginx目录,修改配置文件。非root用户不能使用1024内端口。

    1
    2
    3
    cd /home/zjkapp/soft/nginx/conf
    vim nginx.conf
    ...
  7. 启动和测试

    1
    2
    3
    cd /home/zjkapp/soft/nginx/sbin
    ./nginx -t
    ./nginx

(可选)手动安装pcre和zlib依赖的步骤

  1. 使用zjkapp用户,将pcre-8.43.zip,zlib1211.zip上传到/home/zjkapp/soft目录下
  2. 安装pcre
    1
    2
    3
    4
    5
    cd /home/zjkapp/soft
    unzip pcre-8.43.zip
    cd pcre-8.43
    ./configure --prefix=/home/zjkapp/soft/pcre
    $ make && make install
  3. 安装zlib
    1
    2
    3
    4
    5
    cd /home/zjkapp/soft
    unzip zlib1211.zip
    cd zlib-1.2.11
    ./configure --prefix=/home/zjkapp/soft/zlib
    make && make install
  4. nginx编译检查
    1
    2
    cd /home/zjkapp/soft/nginx-1.18.0
    ./configure --prefix=/home/zjkapp/soft/nginx --with-http_stub_status_module --with-pcre=/home/zjkapp/soft/pcre-8.43 --with-zlib=/home/zjkapp/soft/zlib-1.2.11
    后续步骤参考上边描述。