美文网首页
linux下编译安装nginx

linux下编译安装nginx

作者: 月圆星繁 | 来源:发表于2019-08-18 15:54 被阅读0次
    安装编译工具及库文件

    yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

    安装 PCRE

    PCRE 作用是让 Nginx 支持 Rewrite 功能

    cd /usr/local/src/
    wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
    tar zxvf pcre-8.35.tar.gz
    cd pcre-8.35
    ./configure
    make && make install
    

    可以查看版本:
    pcre-config --version

    下载并解压zlib:
    wget http://www.zlib.net/zlib-1.2.11.tar.gz
    tar zxvf zlib-1.2.11.tar.gz
    
    下载并解压 openssl:
    wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz
    tar zxvf openssl-1.0.1g.tar.gz
    
    创建 Nginx 运行使用的用户 www:
    [root@bogon conf]# /usr/sbin/groupadd www 
    [root@bogon conf]# /usr/sbin/useradd -g www www
    
    安装 Nginx
    cd /usr/local/src/
    wget http://nginx.org/download/nginx-1.14.2.tar.gz(选择合适的版本)
    tar zxvf nginx-1.12.2.tar.gz
    cd nginx-1.12.2
    ./configure --user=www --group=www --prefix=/usr/local/nginx
     --with-http_stub_status_module --with-http_ssl_module 
    --with-http_gzip_static_module --with-pcre=/usr/local/src/pcre-8.35
     --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.0.1g
    

    configure之后没有报错出现如下信息:

    出现这个:
    Configuration summary
      + using system PCRE library
      + using system OpenSSL library
      + using system zlib library
    
      nginx path prefix: "/usr/local/nginx"
      nginx binary file: "/usr/local/nginx/sbin/nginx"
      nginx modules path: "/usr/local/nginx/modules"
      nginx configuration prefix: "/usr/local/nginx/conf"
      nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
      nginx pid file: "/usr/local/nginx/logs/nginx.pid"
      nginx error log file: "/usr/local/nginx/logs/error.log"
      nginx http access log file: "/usr/local/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"
    
    编译与安装

    执行 make && make install

    测试
    [root@localhost sbin]#  /usr/local/nginx/sbin/nginx -v
    nginx version: nginx/1.14.2
    
    • 检查配置文件nginx.conf的正确性命令:
    [root@bogon conf]# /usr/local/nginx/sbin/nginx -t
    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
    
    启动

    在安装完成之后并没有service等命令,可以如下启动:

    /usr/local/nginx/sbin/nginx
    

    查看进程:

    [root@localhost vhost]# ps aux | grep nginx
    root      22742  0.0  0.1  45924  1196 ?        Ss   14:44   0:00 nginx: master process /usr/local/nginx/sbin/nginx
    www       22743  0.1  2.8  73060 28688 ?        S    14:44   0:00 nginx: worker process
    root      22745  0.0  0.0 112724   988 pts/0    R+   14:44   0:00 grep --color=auto nginx
    
    ok!安装完毕!

    相关文章

      网友评论

          本文标题:linux下编译安装nginx

          本文链接:https://www.haomeiwen.com/subject/aewrsctx.html