Mac下nginx配置http2

参考: 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

http://blog.sina.com.cn/s/blog_beebb7590102wwvv.html

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

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

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

输入图片说明

进入到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

效果图: 输入图片说明

转载于:https://my.oschina.net/zhongzhong5/blog/1523319

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值