mac 安装nginx

1. 安装PCRE(这个简单不多说了)

pcre-8.34.tar解压后

cd 到对应目录下。

cd ~
cd pcre-8.34

我直接安装在local里面

sudo ./configure --prefix=/usr/local

sudo make
sudo make install

2、安装或者更新Mac的openssl

我是直接删除掉原有的openssl再重新编译安装。

sudo rm -rf /usr/local/openssl 删除 自己寻找下mac里面的目录,如果没有则跳过这个。

http://www.openssl.org 下载最新的版本

解压之,cd openssl的文件目录

./config --prefix=/usr/local/openssl 指定安装目录 会报下面的警告

Configured for darwin-i386-cc.

wanzhihuideMacBook-Pro:openssl-1.0.2e wanzhihui$ sudo ./config --prefix=/usr/local/ --openssldir=/usr/local/openssl darwin64-x86_64-cc

Operating system: i686-apple-darwinDarwin Kernel Version 15.0.0: Sat Sep 19 15:53:46 PDT 2015; root:xnu-3247.10.11~1/RELEASE_X86_64

WARNING! If you wish to build 64-bit library, then you have to

         invoke './Configure darwin64-x86_64-cc' *manually*.

         You have about 5 seconds to press Ctrl-C to abort.

网上找好了好多都没很好解决。最后发现是

openssl/config脚本猜对你的系统是64位,但是 会根据$KERNEL_BITS来判断是否开启x86_64编译,默认 是不开启的(很奇怪的设置,虽然会给你5秒时间停止编译并手动开启),所以你生成的openssl库文件是32位的,最后静态链接到nginx会出错。目 前看来没有很好的方法把x86_64的参数传到openssl配置文件中 (openssl/config 猜测os架构,设置编译的参数是32位还是64位,默认是32位,然后调用openssl/Configure生成Makefile)

我的解决方法:

找到makefile 将里面的PLATFORM=dist改成

PLATFORM=darwin64-x86_64-cc

在终端工具中再敲入

export KERNEL_BITS=64

sudo ./config darwin64-x86_64-cc  --prefix=/usr/local/openssl 

配置完成

sudo make

编译完成

sudo make install

安装

不编译64位的在安装nginx时会报链接错误。

-L/usr/local/lib -lpcre /usr/local/openssl/lib/libssl.a /usr/local/openssl/lib/libcrypto.a -lz

ld: warning: ignoring file /usr/local/openssl/lib/libssl.a, file was built for archive which is not the architecture being linked (x86_64): /usr/local/openssl/lib/libssl.a

ld: warning: ignoring file /usr/local/openssl/lib/libcrypto.a, file was built for archive which is not the architecture being linked (x86_64): /usr/local/openssl/lib/libcrypto.a

Undefined symbols for architecture x86_64:

  "_ASN1_GENERALIZEDTIME_print", referenced from:

      _ngx_ssl_stapling_ocsp_handler in ngx_event_openssl_stapling.o

  "_ASN1_d2i_bio", referenced from:

      _ngx_ssl_stapling in ngx_event_openssl_stapling.o

  "_BIO_ctrl", referenced from:

      _ngx_ssl_get_raw_certificate in ngx_event_openssl.o

      _ngx_ssl_get_serial_number in ngx_event_openssl.o

      _ngx_ssl_stapling_ocsp_handler in ngx_event_openssl_stapling.o

  "_BIO_free", referenced from:

这样的错误。所以openssl一定要生成正确。

安装nginx

下载最新版本nginx版本 http://nginx.org

1、解压文件,并cd 到目录

2、./configure  --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/usr/local/openssl

3、配置完成 sudo make

4、编译完成 sudo make install

如果PCRE 有自己的指定目录则需要在configure 后面加入路径配置。

这样就可以在local 目录下看到

local xxxx $ ls

bin include lib nginx openssl share ssl

说明安装成功。

sudo /usr/local/nginx/sbin/nginx 启动命令

用浏览器打开 http://localhost 则会出现

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

  
--关闭命令

sudo /usr/local/nginx/sbin/nginx -s stop

配置完成!















你可能感兴趣的:(nginx,mac,openssl)