Mac下nginx配置http2


声明:本文转载自https://my.oschina.net/zhongzhong5/blog/1523319,转载目的在于传递更多信息,仅供学习交流之用。如有侵权行为,请联系我,我会及时删除。

参考: https://www.widlabs.com/article/mac-os-x-nginx-compile-symbol-not-found-for-architecture-x86_64 http://homeway.me/2015/07/10/rebuild-osx-environment/ http://www.jianshu.com/p/9523d888cf77

下载nginx源码,openssl源码压缩包

nginx下载地址:http://nginx.org/en/download.html openssl下载地址:https://www.openssl.org/source/

解压nginx和openssl压缩包,解压之后的目录如下:

输入图片说明 <!-- more -->

进入到nginx目录,使用configure命令,添加https和http2两个模块,

./configure  --with-http_ssl_module --with-http_v2_module --with-openssl=/usr/local/Cellar/openssl-1.0.2l 

执行上面的命令,在输出的信息中,你可能会看到以下信息:

输入图片说明

如果出现以上信息,那么在命令之后完成之后,需要进入到objs目录,然后修改Makefile文件。

在nginx目录下:

cd objs vim Makefile 

找到:

&& ./config --prefix=/usr/local/Cellar/openssl-1.0.2l/.openssl no-shared  \ 

这句,将config替换为:

Configure darwin64-x86_64-cc 

在nginx目录下执行make命令

make 

如果没有按照上一步中的提示修改Makefile文件,则会出现以下错误: 输入图片说明

正常编译完成的输出: 输入图片说明

安装

sudo make install 

安装完成: 输入图片说明

测试nginx安装是否成功

启动nginx

sudo /usr/local/nginx/sbin/nginx 

访问:http:localhost

输入图片说明

出现以上页面说明nginx安装成功了。

开启https

要开启nginx的https,需要生成SSL Key和CSR文件。 如何生成这些文件参考: http://www.jianshu.com/p/9523d888cf77

以下是生成文件之后的目录结构,这里我将文件生成在/usr/local/nginx目录下: 输入图片说明

然后将/user/local/nginx/conf/nginx.conf中,下面这段配置,去掉注释并修改成以下内容:

server {     listen       443 ssl;     server_name  localhost;      ssl_certificate      /usr/local/nginx/server.crt;      ssl_certificate_key  /usr/local/nginx/server.key;      ssl_session_cache    shared:SSL:1m;     ssl_session_timeout  5m;      ssl_ciphers  HIGH:!aNULL:!MD5;     ssl_prefer_server_ciphers  on;      location / {         root   html;         index  index.html index.htm;     } } 

重新加载nginx,在/usr/local/nginx/sbin目录下执行以下命令:

sudo ./nginx -s reload 

输入图片说明

访问https://localhost出现以下页面说明配置成功。 输入图片说明

开启http2

到这一步之后,开启nginx的http2非常简单,只需要将上一步中https的配置中

listen       443 ssl; 

修改为:

listen       443 ssl http2; 

然后重新启动下nginx,再次访问https://localhost

效果图: 输入图片说明

本文发表于2017年08月25日 14:36
(c)注:本文转载自https://my.oschina.net/zhongzhong5/blog/1523319,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如有侵权行为,请联系我们,我们会及时删除.

阅读 2036 讨论 0 喜欢 0

抢先体验

扫码体验
趣味小程序
文字表情生成器

闪念胶囊

你要过得好哇,这样我才能恨你啊,你要是过得不好,我都不知道该恨你还是拥抱你啊。

直抵黄龙府,与诸君痛饮尔。

那时陪伴我的人啊,你们如今在何方。

不出意外的话,我们再也不会见了,祝你前程似锦。

这世界真好,吃野东西也要留出这条命来看看

快捷链接
网站地图
提交友链
Copyright © 2016 - 2021 Cion.
All Rights Reserved.
京ICP备2021004668号-1