zoukankan      html  css  js  c++  java
  • Ubuntu16.04.1 安装Nginx

    一.安装Nginx依赖库

    1.安装gcc g++的依赖库

    apt-get install build-essential
    apt-get install libtool

    2.安装pcre依赖库

    sudo apt-get update
    sudo apt-get install libpcre3 libpcre3-dev

    3.安装zlib依赖库

    sudo apt-get install zlib1g-dev

    4.安装ssl依赖库

    apt-get install openssl

    5.安装Nginx

    #下载最新版本:
    wget http://nginx.org/download/nginx-1.11.3.tar.gz
    #解压:
    tar -zxvf nginx-1.11.3.tar.gz
    #进入解压目录:
    cd nginx-1.11.3
    #配置:
    ./configure --prefix=/usr/local/nginx  
    #编辑nginx:
    make
    注意:这里可能会报错,提示“pcre.h No such file or directory”,具体详见:http://stackoverflow.com/questions/22555561/error-building-fatal-error-pcre-h-no-such-file-or-directory 
    需要安装 libpcre3-dev,命令为:sudo apt-get install libpcre3-dev
    #安装nginx:
    sudo make install
    #启动nginx:
    sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 
    注意:-c 指定配置文件的路径,不加的话,nginx会自动加载默认路径的配置文件,可以通过 -h查看帮助命令。
    #查看nginx进程:
    ps -ef|grep nginx
    ./configure 参数含义:
     --prefix=path    定义一个目录,存放服务器上的文件 ,也就是nginx的安装目录。默认使用 /usr/local/nginx。
     --sbin-path=path 设置nginx的可执行文件的路径,默认为  prefix/sbin/nginx.
     --conf-path=path  设置在nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动,通过命令行中的-c选项。默认为prefix/conf/nginx.conf.
     --pid-path=path  设置nginx.pid文件,将存储的主进程的进程号。安装完成后,可以随时改变的文件名 , 在nginx.conf配置文件中使用 PID指令。默认情况下,文件名 为prefix/logs/nginx.pid.
     --error-log-path=path 设置主错误,警告,和诊断文件的名称。安装完成后,可以随时改变的文件名 ,在nginx.conf配置文件中 使用 的error_log指令。默认情况下,文件名 为prefix/logs/error.log.
     --http-log-path=path  设置主请求的HTTP服务器的日志文件的名称。安装完成后,可以随时改变的文件名 ,在nginx.conf配置文件中 使用 的access_log指令。默认情况下,文件名 为prefix/logs/access.log.
     --user=name  设置nginx工作进程的用户。安装完成后,可以随时更改的名称在nginx.conf配置文件中 使用的 user指令。默认的用户名是nobody。
     --group=name  设置nginx工作进程的用户组。安装完成后,可以随时更改的名称在nginx.conf配置文件中 使用的 user指令。默认的为非特权用户。
     --with-select_module--without-select_module 启用或禁用构建一个模块来允许服务器使用select()方法。该模块将自动建立,如果平台不支持的kqueue,epoll,rtsig或/dev/poll。
     --with-poll_module--without-poll_module 启用或禁用构建一个模块来允许服务器使用poll()方法。该模块将自动建立,如果平台不支持的kqueue,epoll,rtsig或/dev/poll。
     --without-http_gzip_module — 不编译压缩的HTTP服务器的响应模块。编译并运行此模块需要zlib库。
     --without-http_rewrite_module  不编译重写模块。编译并运行此模块需要PCRE库支持。
     --without-http_proxy_module — 不编译http_proxy模块。
     --with-http_ssl_module — 使用https协议模块。默认情况下,该模块没有被构建。建立并运行此模块的OpenSSL库是必需的。
     --with-pcre=path — 设置PCRE库的源码路径。PCRE库的源码(版本4.4 - 8.30)需要从PCRE网站下载并解压。其余的工作是Nginx的./ configure和make来完成。正则表达式使用在location指令和 ngx_http_rewrite_module 模块中。
     --with-pcre-jit —编译PCRE包含“just-in-time compilation”(1.1.12中, pcre_jit指令)。
     --with-zlib=path —设置的zlib库的源码路径。要下载从 zlib(版本1.1.3 - 1.2.5)的并解压。其余的工作是Nginx的./ configure和make完成。ngx_http_gzip_module模块需要使用zlib 。
     --with-cc-opt=parameters — 设置额外的参数将被添加到CFLAGS变量。例如,当你在FreeBSD上使用PCRE库时需要使用:--with-cc-opt="-I /usr/local/include。.如需要需要增加 select()支持的文件数量:--with-cc-opt="-D FD_SETSIZE=2048".
     --with-ld-opt=parameters —设置附加的参数,将用于在链接期间。例如,当在FreeBSD下使用该系统的PCRE库,应指定:--with-ld-opt="-L /usr/local/lib".

    二.Nginx常用命令

    1.启动Nginx

    /usr/local/nginx/sbin/nginx
    ./sbin/nginx 

    2.停止Nginx

    ./sbin/nginx -s stop
    ./sbin/nginx -s quit

    3.Nginx重新加载配置

    ./sbin/nginx -s reload

    4.指定配置文件

    ./sbin/nginx -c /usr/local/nginx/conf/nginx.conf

    5.查看Nginx版本

    1.显示版本(小写v)
    ./sbin/nginx -v
    nginx: nginx version: nginx/1.0.0
    2.显示详细信息(大写)
    ./sbin/nginx -V
    nginx version: nginx/1.11.3
    built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
    built with OpenSSL 1.0.2g  1 Mar 2016
    TLS SNI support enabled
    configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module

    6.检查文件是否正确

    poerchant@ubuntu:/usr/local/nginx$ sudo ./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

    7.显示帮助信息

    ./sbin/nginx -h

    三.Nginx重新编译添加模块

    以下是重新编译的代码和模块

    ./configure --prefix=/usr/local/nginx--with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module

    make 千万别make install,否则就覆盖安装了

    make完之后在objs目录下就多了个nginx,这个就是新版本的程序了

    备份旧的nginx程序

    cp /usr/local/nginx/sbin/nginx/usr/local/nginx/sbin/nginx.bak

    把新的nginx程序覆盖旧的

    cp objs/nginx /usr/local/nginx/sbin/nginx

    测试新的nginx程序是否正确

    /usr/local/nginx/sbin/nginx -t

    nginx: theconfiguration file /usr/local/nginx/conf/nginx.conf syntax is ok

    nginx:configuration file /usr/local/nginx/conf/nginx.conf test issuccessful

    平滑重启nginx

    /usr/local/nginx/sbin/nginx -s reload

  • 相关阅读:
    MySQL第七课
    MySQL第六课
    mysql第五课
    MySQL第四课
    MySQL第三课
    MYSQL第一课
    MYSQL第二课
    char、vchar、nvarchar 的区别
    SSRS Reporting Service安装与部署
    存储过程用法
  • 原文地址:https://www.cnblogs.com/hunter-56213/p/6872582.html
Copyright © 2011-2022 走看看