nginx编译安装on mac
一、编译安装模块
如果是原有包中就有的模块,编译时,./configure --with-xxx 就可以,如果是第三方模块,可使用 --add-module,如果有多个模块的话,只需要多次使用-add-module指令即可.
二、下载源码包image_fliter和echo模块
nginx源码下载http://nginx.org/en/download.htmlecho模块下载https://github.com/openresty/echo-nginx-module/tags解压gzip -d xxx.tar.gztar -zvxf xxx.tar xxx
三.编译
1.安装依赖:
brew install pcrebrew install gd #image filter依赖gdbrew link --force openssl #避免编译openssl时报错
2.cd nginx源码目录
./configure xxx--prefix 设置编译目录
3.查看原有nginx编译参数
nginx -V
4.添加编译module
./configure \ --with-http_image_filter_module \--with-debug \--add-module=/Users/fanfan/web/software/echo-nginx-module-0.61 \原有编译参数,(注意修改版本目录)./configure \--prefix=/usr/local/Cellar/nginx/1.12.2 \--with-http_ssl_module \--with-pcre \--sbin-path=/usr/local/Cellar/nginx/1.12.2/bin/nginx \--with-cc-opt='-I/usr/local/opt/pcre/include -I/usr/local/opt/openssl@1.1/include' \--with-ld-opt='-L/usr/local/opt/pcre/lib -L/usr/local/opt/openssl@1.1/lib' \--conf-path=/usr/local/etc/nginx/nginx.conf \--pid-path=/usr/local/var/run/nginx.pid \--lock-path=/usr/local/var/run/nginx.lock \--http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp \--http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp \--http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp \--http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp \--http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp \--http-log-path=/usr/local/var/log/nginx/access.log \--error-log-path=/usr/local/var/log/nginx/error.log \--with-http_gzip_static_module --with-http_v2_module \--with-http_image_filter_module \--with-debug \--add-module=/Users/fanfan/web/software/echo-nginx-module-0.61------------------------------------------------------------------------------./configure --prefix=/usr/local/nginx-1.4.1 --with-http_stub_status_module \--with-http_realip_module --with-http_image_filter_module --with-debug
5.make
四.安装
1.如果之前未安装nginx
make install
2.如果之前通过brew安装过nginx
/usr/local/bin/nginx/usr/local/Cellar/nginx/xxx/bin/nginx/usr/local/opt/nginx/usr/local/Cellar/nginx/xxx修改软连接,直接指向新的nginx
3.替换编译文件的方式
这种方式,只是替换了bin文件,目录还是原来的#备份原来的binarycp /usr/local/opt/nginx/bin/nginx /usr/local/opt/nginx/bin/nginx.bak#先cd到nginx源码目录sudo cp objs/nginx /usr/local/opt/nginx/bin/nginxrm /usr/local/bin/nginxln -s /usr/local/opt/nginx/bin/nginx /usr/local/bin/nginx
4.建立版本目录方式
$ cp -r /usr/local/Cellar/nginx/1.8.0 /usr/local/Cellar/nginx/1.9.10#先cd到nginx源码目录$ sudo cp objs/nginx /usr/local/Cellar/nginx/1.9.10/bin#更新/usr/local/opt/nginx$ rm /usr/local/opt/nginx$ ln -s /usr/local/Cellar/nginx/xxx /usr/local/opt/nginx#更新/usr/local/bin/nginx$ rm /usr/local/bin/nginx$ ln -s /usr/local/opt/nginx/bin/nginx /usr/local/bin/nginx
5.编辑/Library/LaunchDaemons/homebrew.mxcl.nginx.plist
好像也不用编辑launchctl load -F /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
五.验证nginx
nginx -V / nginx -vyld: Library not loaded: /usr/local/opt/jpeg/lib/libjpeg.8.dylibnginx版本依赖 jpeg 8d的版本,而brew install jpeg 的时候,安装的是新版9b可转换成上一版本即可brew switch jpeg 8d或者 因为其他版本安装出现此问题,可重新安装,rebuild source,这样使用的就是最新版本的依赖brew cleanup //更新cellarbrew reinstall php71 --build-from-sourcehttps://stackoverflow.com/questions/32703296/dyld-library-not-loaded-usr-local-lib-libjpeg-8-dylib-homebrew-php
六.重启nginx
nginx -t //验证配置文件是否正确有可能会有权限问题,启动时,以root用户启动即可sudo brew services restart nginx
七.参考链接
https://blog.chionlab.moe/2016/02/02/compile-nginx-on-osx/https://blog.haohtml.com/archives/12349
作者:糖糖果
来源链接:https://www.cnblogs.com/fanfan259/p/8244536.html
版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。
2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。