URL handling in NginX

Here I explain some url hitting and corresponding configuration in nginx.conf
Example 1) http://localhost/images/example.png
Ans)
server { 
 location / { 
root /data/www; 
}
 location /images/ { 
root /data; 
}
In this case your example.png is situated at /data/images folder on your linux system

Example 2) http://localhost/images/example.png
or
http://localhost/images/example.jpeg
or
http://localhost/images/example.gif
  
Ans)
location ~ \.(gif|jpg|png)$ { root /home/arsingh/; }

In this redirect anything with .gif or .jpg or .png to directory /home/arsingh/images
beacuse it will add images into root path.

Example 3)http://localhost/path2/dir1/aa/bb/cc/dd/ee/eot/ff/gg/hh/images.gif
Ans)
location ~ /pan2/dir1/([^/]*)/([^/]*)/(.*?)/eot/(.*)$ {
add_header value1 $1 ;
add_header value2 $2 ;
add_header value3 $3 ;
add_header value4 $4 ;

alias /home/asingh/images/images.gif;
}

where $1=aa
 $2=bb
$3=cc/dd/ee
$4=gg/hh/images.gif

Example 4)To Handle video content
Ans)
#location ~ /content/video/([^/]*)/(.*)$ {
location ~ /content/video/(.*)$ {
  #  mp4;
  #  mp4_buffer_size    128K;
   # mp4_max_buffer_size   512K;
  #  max_ranges 0;
   # mp4_limit_rate on;
   # mp4_limit_rate_after  30s;  
      add_header Path_Way $1;
    #   add_header ParamStart $2;
      alias D:/<Folder where video is kept>/$1;
}

location ~ /content/planevideo/(.*)$ {
       add_header ParamStart $1;
      alias D:/<Folder where video is kept>/$1;
}


 

No comments:

Post a Comment