nodejsdeveloperskh

serve static files

Apr 7th, 2022 (edited)
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nginx 1.05 KB | None | 0 0
  1. # Serving static files:
  2. # If Nginx could not find the file it will return a 404 page to the user by default.
  3. # But you also can return the directory listing by using autoindex directive
  4.  
  5. server {
  6.     # `root` directive append URI to the root and then tries to return a file.
  7.     root /var/www/data;
  8.     autoindex on;
  9.    
  10.     location / {
  11.         # In this location `root` directive is inherited from its parent section which is `server`
  12.     }
  13.     # Request: GET /images/a.png
  14.     #  - Now Nginx tries to find images in this path: /var/www/data/images/a.png
  15.     # Request: GET /images/a/b
  16.     #  - Now Nginx tries to serve this file: /var/www/data/images/a/b/index.html
  17.     location /images/ {
  18.         # In this location `root` directive is inherited from its parent section which is `server`
  19.     }
  20.     # GET /anything/a.mp3
  21.     #  - If URI ends with .mp3 or .mp4 nginx tries to file the file in this path: /var/www/media/
  22.     #  - In this exmaple it tries to serve /var/www/media/a.mp3
  23.     location ~ \.(mp3|mp4) {
  24.         root /var/www/media;
  25.     }
  26. }
Add Comment
Please, Sign In to add comment