一、編譯安裝模塊
如果是原有包中就有的模塊,編譯時,
./configure --with-xxx 就可以,
如果是第三方模塊,可使用 --add-module,
如果有多個模塊的話,只需要多次使用-add-module指令即可.
二、下載源碼包image_fliter和echo模塊
nginx源碼下載
http://nginx.org/en/download.html
echo模塊下載
https://github.com/openresty/echo-nginx-module/tags
解壓
gzip -d xxx.tar.gz
tar -zvxf xxx.tar xxx
三.編譯
1.安裝依賴:
brew install pcre
brew install gd #image filter依賴gd
brew link --force openssl #避免編譯openssl時報錯
2.cd nginx源碼目錄
./configure xxx
--prefix 設置編譯目錄
3.查看原有nginx編譯參數
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
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文件,目錄還是原來的
#備份原來的binary
cp /usr/local/opt/nginx/bin/nginx /usr/local/opt/nginx/bin/nginx.bak
#先cd到nginx源碼目錄
sudo cp objs/nginx /usr/local/opt/nginx/bin/nginx
rm /usr/local/bin/nginx
ln -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 -v
yld: Library not loaded: /usr/local/opt/jpeg/lib/libjpeg.8.dylib
nginx版本依賴 jpeg 8d的版本,而brew install jpeg 的時候,安裝的是新版9b
可轉換成上一版本即可
brew switch jpeg 8d
或者 因為其他版本安裝出現此問題,可重新安裝,rebuild source,
這樣使用的就是最新版本的依賴
brew cleanup //更新cellar
brew reinstall php71 --build-from-source
https://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