Nginx study concluded: geo and image module (four

Italic, underline, to suggest use the default settings without explicit configuration

一、ngx_http_geo_module

    The core characteristics: based on the client IP (period), geo module will match the variables (for example, country code, city code) specified. geo module that can help us achieve the following scenario:

    1) Simple CDN network

    2) the deployment of multi-room, triage site.

    3) limit illegal IP (period) access, or limiting.

    1、geo 【$address】$variable {...}

        Context: http

    Where "address" variable is optional, if not specified, the default is "$ remote_addr"; use "address" variable value as the client IP, participate geo match, the value of the matched as $ variable. If the "address" variable is not a valid IP address, then use "255.255.255.255" as optional. geo module can use the following parameters:

    1) delete: delete the specified network.

    2) default: If the client IP does not match any information in the geo ip list, will use the default value specified as a value of $ variable. If not using default configuration items, and the match fails, the final $ variable is null.

    3) include: a list of designated geo ip external file. This file is declared in the same way as in geo block, one per line "ip" parameter corresponds to a value.

    4) proxy: those addresses defined trusted (trusted) (usually nginx other cluster address), a request from a trusted addresses will be used in the header field value of "X-Forwarded-For", to match geo. The proxy setting will detect the order of declaration. 

    5) ranges: show addresses define the interval, this parameter is required in the first line of geo block, in accordance with section addresses the need to declare a positive sequence mode.

 

Java code   Collection Code
  1. geo $country {  
  2.     default    US;  
  3.     include    conf/geo.conf;  
  4.     proxy      192.168.1.0/24;  
  5.     ##ip list  
  6.     127.0.0.0/24    US;  
  7.     . 10.1 0.0 / 16 RU;  
  8. }  
  9. server {  
  10.     server_name .exmaple.org;  
  11.     $if($country != US) {  
  12.         rewrite ^/(.*)$ http://$country.example.org/$! last;  
  13.     }  
  14. }  
  15. server {  
  16.     server_name us.example.org;  
  17.     location / {  
  18.         ....  
  19.     }  
  20. }  

 

Java code   Collection Code
  1. geo $country {  
  2.     ranks;  
  3.     default    US;  
  4.     . 127.0 At the 0.0- . 127.0 0.0 US; ## range, said to "-" Segmentation  
  5.     . 127.0 0.1 to . 127.0 0.1 RU;  
  6. }  

 

二, ngx_http_image_fileter_module

    Picture Crop Assistance module, which requires additional installation, and the installation process is relatively complicated, see [ installation ].

    1、image_filter

        Context: location

    Fashion image processing, syntax:

    

Java code   Collection Code
  1. image_filter off;  
  2. image_filter test;  
  3. image_filter size;  
  4. imagefilter rotate 90 | 180 | 270;  
  5. image_filter resize 【width】 【height】;  
  6. image_filter crop 【width】 【height】;  

    1) off: in this block location, turn off this processing module.

    2) test: Make sure the image format in response to JPEG, GIF, PNG, otherwise it will return an error code 415 (Unsupported Media Type). This parameter can be used to detect the image URL is "well-formed" picture.

    3) size: the size of information output in response to the image (without picture output stream) to json format, if an error is returned empty JSON.

Java code   Collection Code
  1. "img" : { "width": 100, "height": 100, "type": "gif" } }  

 

 

    4) rotate 90 | 180 | 270: counterclockwise rotation angle specified picture. Alternatively value is "90", "180", "270", this instruction may be used alone, or may be "a resize" used with "Crop Allows you."

    5) resize [width] [height]: scale the size of the compressed image; If you only want compressed in one dimension, with other dimensions may be "_" indicates. If an error occurs, it returns an error code 415. When this parameter is used in conjunction with rotate, then compressed too will rotate. resize that is, we often say "geometric compression", the picture after the final compression length and width will not exceed the value of the parameter specified.

    6) crop [width] [height]: crop, according to the first long side of the picture geometric compression (with resize), and then use the shorter side of the crop. If this configuration has rotate, rotate it first and then crop.

 

    Picture resize, when crop, throws 415 error because the investigation ways: nginx has permission to access this file (if not, do not throw 403, but directly 415), whether the system is related to the type of treatment lib installation of Media the size of the picture exceeds the size of the "image_filter_buffer" of.

 

    2、image_filter_buffer 【size】

        The default is "1M"; set the maximum memory space needed to read the picture, if the picture is larger than this value, the 415 error is returned.

    3、image_filter_jpeg_quality 【quality】

        The default value is "75"; jpeg format image compression quality. The lower the quality, the smaller the size of the transmitted data; recommended maximum of 95.

    4、image_filter_sharpen 【percent】

        The default value is "0"; increase the sharpness of the picture. "0" indicates that close sharpness.

    5、image_filter_transparency 【on | off】

        The default is "on"; for pictures PNG, GIF formats, whether to retain the transparency of the original picture.

Java code   Collection Code
  1. server {  
  2.     server_name img.example.org;  
  3.     location / {  
  4.         root www/images;  
  5.         image_filter resize $ arg_width $ arg_height; # request parameters width, height  
  6.     }  
  7. }  

 

The paper switched from https://www.iteye.com/blog/shift-alt-ctrl-2229578

Fleeting, when you see people better than you than when you hard, you will be more outstanding, I believe that the harder the more lucky!

Guess you like

Origin www.cnblogs.com/knownfreestyle/p/11433723.html