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

简介:

现在很多网站要求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;

   }

}











本文转自 lirulei90 51CTO博客,原文链接:http://blog.51cto.com/lee90/1885188,如需转载请自行联系原作者
目录
相关文章
|
3月前
|
缓存 应用服务中间件 网络安全
Nginx中配置HTTP2协议的方法
Nginx中配置HTTP2协议的方法
245 7
|
2月前
|
应用服务中间件 Linux 网络安全
nginx安装部署ssl证书,同时支持http与https方式访问
为了使HTTP服务支持HTTPS访问,需生成并安装SSL证书,并确保Nginx支持SSL模块。首先,在`/usr/local/nginx`目录下生成RSA密钥、证书申请文件及自签名证书。接着,确认Nginx已安装SSL模块,若未安装则重新编译Nginx加入该模块。最后,编辑`nginx.conf`配置文件,启用并配置HTTPS服务器部分,指定证书路径和监听端口(如20000),保存后重启Nginx完成部署。
866 8
|
3月前
|
Web App开发 算法 应用服务中间件
nginx开启局域网https访问
【10月更文挑战第22天】为了调试WebRTC功能,需要在局域网内搭建HTTPS协议。具体步骤包括:在已部署Nginx和安装OpenSSL的环境中生成私钥、证书签名请求和自签名证书;将生成的文件放置到Nginx的证书目录并修改Nginx配置文件,最后重启Nginx服务。注意,自签名证书不受第三方机构认可,如需正式使用,需向CA申请签名。
128 2
|
5月前
|
应用服务中间件 nginx Docker
Docker镜像-基于DockerFile制作编译版nginx镜像
这篇文章介绍了如何基于Dockerfile制作一个编译版的nginx镜像,并提供了详细的步骤和命令。
709 17
Docker镜像-基于DockerFile制作编译版nginx镜像
|
4月前
|
安全 应用服务中间件 Shell
nginx配置https的ssl证书和域名
nginx配置https的ssl证书和域名
|
4月前
|
Docker 容器
docker nginx-proxy 添加自定义https网站
docker nginx-proxy 添加自定义https网站
65 4
|
5月前
|
网络协议 算法 数据安全/隐私保护
HTTP2和HTTP3区别?HTTP2有什么缺点?
总的来说,如果把HTTP/2比作是优化过的汽车,那HTTP/3就像是直升飞机,它不仅飞得快,而且即使前面有障碍也不会轻易停下。想要网站速度更快,HTTP/3无疑提供了更好的选择。
351 3
|
5月前
|
安全 应用服务中间件 网络安全
简单比较 http https http2,我们要如何把http升级为https
【9月更文挑战第13天】本文对比了HTTP、HTTPS和HTTP/2的特点与适用场景。HTTP以明文传输,适合低安全要求的环境;HTTPS通过SSL/TLS加密,适用于电子商务等安全要求高的场景;HTTP/2采用二进制格式和多路复用,适合高性能Web应用。文章还详细介绍了将HTTP升级为HTTPS的步骤,包括申请和安装SSL证书、配置Web服务器、重定向HTTP流量到HTTPS以及测试HTTPS功能。升级到HTTPS可提高数据安全性和用户信任度。
143 13
|
4月前
|
应用服务中间件 nginx C++
nginx的cgi模块
nginx的cgi模块
81 0
|
6月前
|
缓存 应用服务中间件 nginx
安装nginx-http-flv-module模块
本文介绍如何为Nginx安装`nginx-http-flv-module`模块。此模块基于`nginx-rtmp-module`二次开发,不仅具备原模块的所有功能,还支持HTTP-FLV播放、GOP缓存、虚拟主机等功能。安装步骤包括:确认Nginx版本、下载相应版本的Nginx与模块源码、重新编译Nginx并加入新模块、验证模块安装成功。特别注意,此模块已包含`nginx-rtmp-module`功能,无需重复编译安装。
396 1