CentOS 7编译安装nginx详解

CentOS 安装Nginx+动态模块
参考
官方安装教程

安装Nginx
cd /tmp && mkdir nginx && cd nginx
$ wget https://nginx.org/download/nginx-1.17.9.tar.gz && tar -zxf nginx-1.17.9.tar.gz

Install optional Nginx dependencies:

yum install -y perl perl-devel perl-ExtUtils-Embed libxslt libxslt-devel libxml2 libxml2-devel gd gd-devel GeoIP GeoIP-devel
#缺少c++编译器
yum -y install gcc-c++ autoconf automake
下载依赖组件pcre
$ wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz && tar -zxf pcre-8.44.tar.gz
下载依赖组件zlib
wget http://zlib.net/zlib-1.2.11.tar.gz && tar -zxf zlib-1.2.11.tar.gz
下载依赖组件openssl
wget wget http://www.openssl.org/source/openssl-1.1.1d.tar.gz && tar -zxf openssl-1.1.1d.tar.gz
安装依赖组件pcre

cd nginx-1.17.9

./configure --prefix=/etc/nginx
--sbin-path=/usr/sbin/nginx
--modules-path=/usr/lib64/nginx/modules
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock
--user=nginx
--group=nginx
--build=CentOS
--builddir=nginx-1.15.7
--with-select_module
--with-poll_module
--with-threads
--with-file-aio
--with-http_ssl_module
--with-http_v2_module
--with-http_realip_module
--with-http_addition_module
--with-http_xslt_module=dynamic
--with-http_image_filter_module=dynamic
--with-http_geoip_module=dynamic
--with-http_sub_module
--with-http_dav_module
--with-http_flv_module
--with-http_mp4_module
--with-http_gunzip_module
--with-http_gzip_static_module
--with-http_auth_request_module
--with-http_random_index_module
--with-http_secure_link_module
--with-http_degradation_module
--with-http_slice_module
--with-http_stub_status_module
--with-http_perl_module=dynamic
--with-perl_modules_path=/usr/lib64/perl5
--with-perl=/usr/bin/perl
--http-log-path=/var/log/nginx/access.log
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp
--with-mail=dynamic
--with-mail_ssl_module
--with-stream=dynamic
--with-stream_ssl_module
--with-stream_realip_module
--with-stream_geoip_module=dynamic
--with-stream_ssl_preread_module
--with-compat
--with-pcre=../pcre-8.44
--with-pcre-jit
--with-zlib=../zlib-1.2.11
--with-openssl=../openssl-1.1.1d
--with-openssl-opt=no-nextprotoneg
--with-debug

make
make install
#建立软连接,方便dynamic load_module
sudo ln -s /usr/lib64/nginx/modules /etc/nginx/modules

vim /etc/nginx/nginx.conf
#在nginx.conf文件顶部引用
load_module modules/ngx_http_image_filter_module.so
#启动nginx
nginx
#停止nginx
nginx -s stop
#更改config文件后,重新加截
nginx -s reload
#查看安装结果(大V)
nginx -V
#查看运行结果
netstat -anp|grep 8080
ps aux|grep nginx

编写配置,类似

    location ~ /room-thumbnail/(.*)[^_\d+]\.(jpeg|jpg|png|gif|webp) {
       alias /Users/baisheng2/application/upload/room-thumbnail/$1.$2;
    }

    location ~ /room-thumbnail/(.*)_(\d+)_(\d+)\.(jpeg|jpg|png|gif|webp) {
       alias /Users/baisheng2/application/upload/room-thumbnail/$1.$4;
       set $img_w $2;
       set $img_h $3;

        if ($img_w = 0) {
            set $img_w -;
        }
        
        if ($img_h = 0) {
            set $img_h -;
        }

       image_filter   resize  $img_w $img_h;
       image_filter_buffer 2M;
       try_files /Users/baisheng2/application/upload/room-thumbnail/$1.$4 @qwe;
    }

    # location ~ .*\.(jpeg|jpg|png|gif|webp) {
    #     try_files /Users/baisheng2/application/upload/room-thumbnail/$1.$4 @qwe;
    # }

    location @qwe {
        rewrite ^/(.*)$  /img/notfound.png;
    }

    location ^~ /img/notfound.png {
        alias /Users/baisheng2/application/upload/tmp/notfound.png;
        image_filter   resize  200 -;
    }

你可能感兴趣的:(CentOS 7编译安装nginx详解)