阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

编译Nginx支持https+http2+nginx-http-concat模块

177次阅读
没有评论

共计 3500 个字符,预计需要花费 9 分钟才能阅读完成。

现在很多网站要求 https 访问,既能提高安全性,也避免运营商劫持。又必须给 nginx 加上这些功能。

注意:编译 nginx 需要安装好 gcc gcc-c++

pcre 下载地址:

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

我用的是 8.39 版本的 pcre

openssl 源码包下载地址:

https://www.openssl.org/source/ 或者 https://github.com/openssl/openssl/releases/

nginx-http-concat 源码包下载地址:

https://github.com/alibaba/nginx-http-concat

nginx-http-concat 用法说明:

https://www.nginx.com/resources/wiki/modules/concat/

https://github.com/alibaba/nginx-http-concat

nginx 版本:

nginx-1.11.5.tar.gz (官网下载)

准备源文件:

这些软件的源代码及解压后存放在 /home/tools/,步骤略过。

1、修改下 nginx-http-concat 源码:

编辑 ngx_http_concat_module.c  修改第 33 行,将原先的 x -javascript 改成 javascript 保存退出。(具体原因请 google)

2、编译安装 nginx

groupadd web

useradd -g web web

cd /home/tools/nginx-1.11.5

./configure –prefix=/alidata/server/nginx \

–user=web –group=web \

–with-http_stub_status_module –with-http_ssl_module \

–with-http_gunzip_module –with-http_gzip_static_module \

–with-http_realip_module –with-file-aio \

–with-http_secure_link_module –with-http_auth_request_module \

–with-http_random_index_module –with-http_addition_module \

–with-poll_module –with-select_module \

–with-pcre=/home/tools/pcre-8.39 \

–add-module=/home/tools/nginx-http-concat \

–with-http_v2_module \

–with-openssl=/home/tools/openssl-1.1.0c

make -j 4 && make install

echo ‘export PATH=/alidata/server/nginx/sbin:$PATH’ > /etc/profile.d/nginx.sh

source /etc/profile.d/nginx.sh

然后在 nginx.conf 里面配置上:

server {

listen 80;

server_name 192.168.2.11;

root /alidata/wwwroot;

index index.html index.php;

location / {

root /alidata/wwwroot;

index index.html index.php;

              # 下面的可根据实际的业务环境来配,这里演示就都给列出来了

      concat on;

  concat_max_files 20;

  concat_unique off;

}

        # 下面的可根据实际的业务环境来配,这里演示就都给列出来了

location /static/css/ {

  concat on;

  concat_max_files 20;

    concat_unique off;

}

location /static/js/ {

  concat on;

  concat_max_files 30;

    concat_unique off;

}

}

使用方法:

准备 2 个 js 文件 1.js 和 2.js,放在 /alidata/wwwroot 目录下。

        我们可以在浏览器单独访问 http://192.168.2.11/1.js 和 http://192.168.2.11/2.js

        也可以使用 http://192.168.2.11/??1.js,2.js 这种方式同时加载 2 个 js 文件,这就是 nginx-http-concat 的作用。

https 的配置也差不多,类似下面这种:

server {

  listen 443;

  ssl on;

  ssl_certificate /data/web/nginx_key/1_www.demo.com_bundle.crt;

  ssl_certificate_key /data/web/nginx_key/2_www.demo.com.key;

  server_name  www.demo.com;

  access_log  /home/wwwlogs/demo.access.log;

  error_log  /home/wwwlogs/demo.error.log;

  root  html;

  index  index.html index.htm index.php;

  ## send request back to tomcat ##

  location / {

      proxy_pass  https://127.0.0.1:8443;

     

      # Proxy Settings

      proxy_redirect    off;

      proxy_set_header  Host            $host;

      proxy_set_header  X-Real-IP        $remote_addr;

      proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;

      proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;

      proxy_max_temp_file_size 0;

      proxy_connect_timeout      90;

      proxy_send_timeout        90;

      proxy_read_timeout        90;

      proxy_buffer_size          4k;

      proxy_buffers              4 32k;

      proxy_busy_buffers_size    64k;

      proxy_temp_file_write_size 64k;

  }

}

下面关于 Nginx 的文章您也可能喜欢,不妨参考下:

CentOS 7.2 下编译安装 PHP7.0.10+MySQL5.7.14+Nginx1.10.1  http://www.linuxidc.com/Linux/2016-09/134804.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

Linux 下编译安装 Nginx 1.8.1 及配置 http://www.linuxidc.com/Linux/2017-02/140495.htm

CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

Nginx 日志过滤 使用 ngx_log_if 不记录特定日志 http://www.linuxidc.com/Linux/2014-07/104686.htm

Nginx 的 500,502,504 错误解决方法 http://www.linuxidc.com/Linux/2015-03/115507.htm

CentOS 7 编译安装 Nginx1.10.2 脚本启动失败解决思路 http://www.linuxidc.com/Linux/2017-01/139794.htm

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-02/141023.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计3500字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中