zoukankan      html  css  js  c++  java
  • 编译安装nginx1.16.1

    这边有个不错的编译安装的步骤,来记录一下
    1、安装预处理环境

    [root@localhost ~]# dnf install -y lrzsz  psmisc lsof wget ntpdate gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools iotop bc zip unzip zlib-devel  nfs-utils automake libxml2 libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed gd-devel GeoIP GeoIP-devel
    

    2、下载包并解压

    wget -O /usr/local/nginx-1.16.1.tar.gz http://nginx.org/download/nginx-1.16.1.tar.gz
    tar xf /usr/local/nginx-1.16.1.tar.gz -C /usr/local
    

    3、编译选项

    cd nginx-1.16.1
    ./configure --prefix=/usr/local/nginx  --with-http_ssl_module 
                --with-http_v2_module  
                --with-http_realip_module 
                --with-http_addition_module  
                --with-http_image_filter_module 
                --with-http_geoip_module 
                --with-http_gunzip_module 
                --with-http_stub_status_module 
                --with-http_gzip_static_module 
                --with-pcre 
                --with-stream 
                --with-stream_ssl_module 
                --with-stream_realip_module
    

    4、编译及安装

    [root@localhost nginx-1.16.1]# make && make install                      #创建目录,并将生成的模块和文件件复制到相应的目录:
    

    5、添加nginx用户

    [root@master2 nginx-1.16.1]# useradd nginx -s /sbin/nologin -u 2000                                  #以普通用户启动nginx
    [root@master2 nginx-1.16.1]# chown nginx.nginx -R /usr/local/nginx                                   #授权
    

    nginx安装完毕之后,在/usr/local/nginx目录下面能够看到几个目录

    [root@master2 nginx-1.16.1]# cd /usr/local/nginx
    [root@master2 nginx]# ls
    conf  html  logs  sbin
    

    conf:该目录中保存了nginx所有的配置文件,其中nginx.conf是nginx服务器的最核⼼最主要的配置文件,其他的.conf则是用来配置nginx相关的功能的,例如fastcgi功能使用的是fastcgi.conf和fastcgi_params两个文件,配置文件一般都有个样板配置文件,是文件名.default结尾,使用时将其复制为并将default去掉即可。
    html:该目录中保存了nginx服务器的web文件,但是可以更改为其他目录保存web文件,另外还有一个50x的web文件是默认的错误页面提示页面。
    logs:该目录用来保存nginx服务器的访问日志错误日志等日志,logs目录可以放在其他路径,比如/var/logs/nginx里面。
    sbin:该目录用来保存nginx二进制启动脚本,可以接受不同的参数以实现不同的功能。

    6、验证版本

    [root@master2 nginx]# sbin/nginx -V
    nginx version: nginx/1.16.1
    built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
    built with OpenSSL 1.0.2k-fips  26 Jan 2017
    TLS SNI support enabled
    configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_image_filter_module --with-http_geoip_module --with-http_gunzip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
    

    7、启动nginx并访问

    [root@master2 nginx]# sbin/nginx 
    

    一些排错问题

    这是后续慢慢自己总结的一些。
    1、今天遇到一个学员的问题。在执行make install 的时候,报了错误,详细的错误是Error: mkdir: cannot create directory ‘/srv/nginx --with-file-aio File name too long就是这种类似的,这是在make install 阶段。一般来说,make install阶段出现问题主要有权限问题,比如使用普通用户进行make install可能写不进去prefix指定的目录,改成使用root用户就可以了。但是这次不一样,报的错误是不能创建目录,其实在make install阶段报错只是把问题表现出来了,实际上configure阶段就有问题了,只是没有明显的错误,执行echo $?你会发现也是显示结果为0,表示成功。经过后续的仔细研究,发现在configure的命令中出现了可疑字符问题。如下所示:

    [root@localhost nginx-1.16.1]# cat -A a.sh
    ./configure $
    --prefix=/srv/nginxM-BM- $
    --with-file-aioM-BM- $
    --with-http_auth_request_moduleM-BM-  $
    --with-http_ssl_module $
    --with-http_addition_moduleM-BM- $
    --with-http_xslt_module=dynamicM-BM- $
    --with-http_geoip_module=dynamicM-BM- $
    

    也就是里面的M-BM-字符,这种字符会导致我们命令直接不可用,但是看不到的,只能使用cat -A把所有的字符都显示出来才行。所以我们要去掉,很简单,如下命令所示:

    sed -i 's/xc2xa0/ /g' a.sh
    

    这样就可以去掉特殊字符了、

  • 相关阅读:
    Building Java Projects with Gradle
    Vert.x简介
    Spring及Spring Boot 国内快速开发框架
    dip vs di vs ioc
    Tools (StExBar vs Cmder)which can switch to command line window on context menu in windows OS
    SSO的定义、原理、组件及应用
    ModSecurity is an open source, cross-platform web application firewall (WAF) module.
    TDD中测试替身学习总结
    Spring事务银行转账示例
    台式机(华硕主板)前面板音频接口(耳机和麦克风)均无声的解决办法
  • 原文地址:https://www.cnblogs.com/FengGeBlog/p/13534156.html
Copyright © 2011-2022 走看看