• nginx(1)-linux环境下安装nginx


    开始安装nginx

    https://nginx.org/download/

    在安装nginx前首先要确认系统中安装了pcre-devel、gcczlib-devel、openssl-devel


    先解决apache安装依赖包 aprapr-utilpcre

     http://apr.apache.org 下载apr-1.4.6.tar.gz和apr-util-1.5.1.tar.gz
    http://www.pcre.org/ 下载pcre-8.32.tar.gz
    (版本不一定非要下载此版本)
    ·
    先装gcc和make(原因:发现nigix是弹过源码包发布的,而nginx是c写的,因此需要安装c/c++的编译器

    yum -y install gcc
    yum -y install make
    yum -y install gcc-c++ 没有这个gcc-c++一会编译不pcre
    yum -y install expat-devel 这个不装apr-util无法使用make

    安装apr:

    wget http://archive.apache.org/dist/apr/apr-1.4.6.tar.gz

    tar -zvxf apr-1.4.6.tar.gz

    把解压后的文件移动到/usr/local
    cd apr-1.4.6
    ./configure --prefix=/usr/local/apr  (注意!在此步操作之前local是没用apr这个文件夹的,是操作这个命令后生成的)
    make && make install




    安装apr-util

    wget http://archive.apache.org/dist/apr/apr-util-1.5.1.tar.gz  


    tar -zvxf apr-util-1.5.1.tar.gz
    cd apr-util-1.5.1
    编译:./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr  
                                  (注意!在此步操作之前local是没用apr这个文件夹的,是操作这个命令后生成的,安装这个把之前安装的apr也带上)
    安装:make && make install


    安装pcre(目的: Nginx 支持 Rewrite 功能

    https://ftp.pcre.org/pub/pcre/  用这个链接下载pcre

    wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

    然后把包上传到Linux服务器上

    tar jxvf pcre-8.00.tar.bz2

    cd pcre-8.00
    ./configure  --prefix=/usr/local/pcre
    make && make install

    查看版本:pcre-config --version

     

    zlib-devel

    yum install -y zlib-devel  (我只安装了这个,如果有错误再安装下面的zlib)

    -------------以下忽略暂时没装

    缺少zlib,我们需要再次安装zlib

    http://www.zlib.net/

    zlib同样是tar.gz来管理的,先解压

    先解压

    发现zlib也是由源码包管理的,来安装zlib

    ./configure

    make install

    安装完毕,来安装nginx

    ./configure

    make install

    这次终于安装成功。

    nginx安装

    http://nginx.org/en/download.html 下载稳定版本

     ## 解压tar -zxvf nginx-1.9.9.tar.gz

    ##进入nginx目录

    cd nginx-1.9.9

    配置./configure --prefix=/usr/local/nginx
    make && make install

     

    在编译nginx这一步我遇到了问题:

    ./configure: error: the HTTP rewrite module requires the PCRE library.
    You can either disable the module by using --without-http_rewrite_module
    option, or install the PCRE library into the system, or build the PCRE library
    statically from the source with nginx by using --with-pcre=<path> option.

    错误为:./configure: error: the HTTP rewrite module requires the PCRE library.

    安装pcre-devel解决问题
    yum -y install pcre-devel

    还有可能出现:

    错误提示:./configure: error: the HTTP cache module requires md5 functions
    from OpenSSL library.   You can either disable the module by using
    --without-http-cache option, or install the OpenSSL library into the system,
    or build the OpenSSL library statically from the source with nginx by using
    --with-http_ssl_module --with-openssl=<path> options.

    解决办法:

    yum -y install openssl openssl-devel

    上面修改安装完毕后

    再次执行

    配置./configure --prefix=/usr/local/nginx 不再报错
    make && make install

    安装后在linux下启动和关闭nginx:

    启动操作

    cd /usr/local/nginx/sbin (./nginx -t 查看配置信息是否正确)
    ./nginx -t 



    启动nginx

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

    重启nginx  #  ./nginx   -s   reload

    停止nginx  #  ./nginx   -s   stop

    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] still could not bind()

    担心端口冲突,提前把端口进行修改,/usr/local/nginx/conf/nginx.conf,

    我改成了18081端口号

    重启时又发现报错:

    [root@localhost sbin]# ./nginx -s reload
    nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)

      [root@localhost sbin]# ./nginx -s reload

      nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)

      解决方法:

      cd /usr/local/nginx

      [root@localhost nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

      使用nginx -c的参数指定nginx.conf文件的位置

      [root@localhost nginx]# cd logs/

      [root@localhost logs]# ll

      总用量 12

      -rw-r--r-- 1 root root 1246 12月 9 18:10 access.log

      -rw-r--r-- 1 root root 516 12月 10 15:39 error.log

      -rw-r--r-- 1 root root 5 12月 10 15:38 nginx.pid

      看nginx.pid文件已经有了。

    解决完,再重启nginx

    cd /usr/local/nginx/sbin

    重启nginx  #  ./nginx   -s   reload

    然后看下端口是否已经修改成功,netstat -ntlp

    [root@localhost sbin]# whereis nginx
    nginx: /usr/local/nginx

    开始从浏览器访问nginx:

    http://192.168.11.14:18081

    访问成功!

    参考文章:https://blog.51cto.com/13658403/2105586  

  • 相关阅读:
    一句话木马
    JNLP介绍
    游戏是如何检测到有OD等调试工具的
    反调试技巧总结原理和实现
    .do百度百科
    Dadong's JSXX 0.39 VIP所用shellcode调试
    strcat
    C++:Singleton模式
    Win32:即给编辑框添加新窗口过程,也保留原来的窗口过程属性
    摘:C语言数字转换为字符串
  • 原文地址:https://www.cnblogs.com/yiyaxuan/p/12516938.html
Copyright © 2020-2023  润新知