安裝成功的nginx,如何新增未編譯安裝模組(非覆蓋安裝http_image_filter_module)

小雷FansUnion發表於2015-11-06
背景:
1.做了圖片上傳小專案。
2.圖片上傳,需要多圖管理。
3.圖片上傳,需要儲存到Fastdfs。
4.Fastdfs上的圖片,和Nginx結合。
5.Nginx從Fastdfs獲得的圖片,需要使用縮圖。
a.在不需要縮圖,小圖的情況下,可以使用原圖。
b.需要縮圖的情況下,指定目標寬度和高度,獲得指定寬度和高度的縮圖。


關鍵的幾個參考資料
1.安裝成功的nginx如何新增未編譯安裝模組
http://blog.csdn.net/gebitan505/article/details/17612845
2.nginx命令:啟動,停止及命令引數詳解
http://blog.csdn.net/aidenliu/article/details/6413342
3.nginx圖片過濾處理模組http_image_filter_module安裝配置筆記
http://www.cnblogs.com/tintin1926/archive/2012/07/11/2586624.html




第1步:檢視nginx編譯安裝時的命令,安裝了哪些模組
/usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.8.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) 
configure arguments: --add-module=/root/soft/fastdfs-nginx-module-master/src  


    cd /root/soft/nginx-1.8.0
./configure --prefix=/root/soft/ --add-module=/root/soft/fastdfs-nginx-module-master/src --with-http_image_filter_module --with-http_realip_module  --with-debug
報錯啦
./configure: error: the HTTP image filter module requires the GD library.
You can either do not enable the module or install the libraries.

第2步:安裝the GD library
#這種不行,我自己YY的
yum install gd
Running Transaction
  Installing : libXpm-3.5.10-2.el6.x86_64                                                                                                       1/2 
  Installing : gd-2.0.35-11.el6.x86_64                                                                                                          2/2 
  Verifying  : libXpm-3.5.10-2.el6.x86_64                                                                                                       1/2 
  Verifying  : gd-2.0.35-11.el6.x86_64                                                                                                          2/2 


Installed:
  gd.x86_64 0:2.0.35-11.el6                                                                                                                         


Dependency Installed:
  libXpm.x86_64 0:3.5.10-2.el6                                                                                                                      


Complete!
按照自己yy的方式,無法啟動。
百度搜尋“the HTTP image filter module requires the GD library”,找到以下方式~
#這種方式可以
yum install gd-devel
Installed:
  gd-devel.x86_64 0:2.0.35-11.el6                                                                                                                   


Dependency Installed:
  fontconfig-devel.x86_64 0:2.8.0-5.el6               freetype-devel.x86_64 0:2.3.11-15.el6_6.1          libX11-devel.x86_64 0:1.6.0-6.el6         
  libXau-devel.x86_64 0:1.0.6-4.el6                   libXpm-devel.x86_64 0:3.5.10-2.el6                 libXt.x86_64 0:1.1.4-6.1.el6              
  libjpeg-turbo-devel.x86_64 0:1.2.1-3.el6_5          libpng-devel.x86_64 2:1.2.49-1.el6_2               libxcb-devel.x86_64 0:1.9.1-3.el6         
  xorg-x11-proto-devel.noarch 0:7.7-9.el6            


Dependency Updated:
  fontconfig.x86_64 0:2.8.0-5.el6     freetype.x86_64 0:2.3.11-15.el6_6.1     libX11.x86_64 0:1.6.0-6.el6     libX11-common.noarch 0:1.6.0-6.el6    
  libxcb.x86_64 0:1.9.1-3.el6        


Complete!


第3步:這個目錄下有二進位制檔案
/root/soft/nginx-1.8.0/objs


仍然在“/root/soft/nginx-1.8.0”這個目錄下


原來的nginx二進位制檔案
-rwxr-xr-x 1 root root 3322288 Oct 29 14:29 nginx


編譯生成的Nginx
-rwxr-xr-x 1 root root 3480087 Nov  5 18:10 nginx
稍微變大了一點,這應該是增加了一個模組的效果


cp ./objs/nginx /usr/local/nginx/sbin/  


[root@AY1304131823374920ac nginx-1.8.0]# cp ./objs/nginx /usr/local/nginx/sbin/ 
cp: overwrite `/usr/local/nginx/sbin/nginx'? y
cp: cannot create regular file `/usr/local/nginx/sbin/nginx': Text file busy


第4步:停止Nginx的2個程式,再次cp
[root@AY1304131823374920ac conf]# ps -ef|grep nginx
root     11648  5064  0 18:18 pts/0    00:00:00 grep nginx
root     30321     1  0 Oct29 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody   30322 30321  0 Oct29 ?        00:00:08 nginx: worker process      
[root@AY1304131823374920ac conf]# ps -ef|grep nginx
root     11668  5064  0 18:19 pts/0    00:00:00 grep nginx
root     30321     1  0 Oct29 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody   30322 30321  0 Oct29 ?        00:00:08 nginx: worker process      
[root@AY1304131823374920ac conf]# kill -9 30321
[root@AY1304131823374920ac conf]# ps -ef|grep nginx
root     11670  5064  0 18:19 pts/0    00:00:00 grep nginx
nobody   30322     1  0 Oct29 ?        00:00:08 nginx: worker process      
[root@AY1304131823374920ac conf]# kill -9 30322
[root@AY1304131823374920ac conf]# ps -ef|grep nginx
root     11672  5064  0 18:19 pts/0    00:00:00 grep nginx
重新執行cp命令




第5步:檢查配置,發現啟動報錯
[root@AY1304131823374920ac conf]# /usr/local/nginx/sbin/nginx -t
nginx: [alert] could not open error log file: open() "/root/soft//logs/error.log" failed (2: No such file or directory)
2015/11/05 18:20:52 [emerg] 11697#0: open() "/root/soft//conf/nginx.conf" failed (2: No such file or directory)
nginx: configuration file /root/soft//conf/nginx.conf test failed


應該是編譯製定了--prefix /root/soft導致的,之前安裝的時候,沒有指定,預設可能是“/usr/local”.


第6步:可以通過指定配置檔案的路徑,來啟動~
nginx -c </path/to/config>
  此命令引數指定一個新的nginx配置檔案來替換預設的nginx配置檔案,如果你不確定新的nginx配置檔案語法是否正確,你可以通過nginx命令-t引數來測試,-t引數代表不執行配置檔案,而僅僅只是測試配置檔案,即
nginx -t -c </path/to/config>


這次,我還是重新編譯算了~
./configure --prefix=/usr/local/nginx --add-module=/root/soft/fastdfs-nginx-module-master/src --with-http_image_filter_module --with-http_realip_module  --with-debug
make
cp ./objs/nginx /usr/local/nginx/sbin/  


第7步:image_filter指令,不會再報錯了。
location ~ group1/M00/(.+)\.?(.+){
          alias /home/fastdata/data;
            ngx_fastdfs_module;
image_filter resize  200 220;
      }

相關文章