NGINX: Serve ONLY specific file types in all directories

I only need to serve the .vmdk and .vmx files on the virtual server, no matter what directory level. This is my current configuration (now it serves everything, but if I uncomment the bottom, it does not serve anything):

server { listen 80; server_name vmdk; access_log /var/log/nginx/localhost.access.log; root /srv/vmdk/public; location ~ (./?|\vmdk|\vmx)$ { autoindex on; } #location / { # deny all; #} } 

How do I achieve this?

If Apache is easier to achieve, then an example Apache configuration will also be appreciated.

+6
source share
1 answer

This should work

 server { listen 80; server_name vmdk; access_log /var/log/nginx/localhost.access.log; root /srv/vmdk/public; location / { deny all; # deny by default location ~ "\.(vmdk|vmx)$" { allow all; # allow vm disk images, etc. } location ~ "/$" { allow all; autoindex on; # allow listing directory contents } } } 
+5
source

Source: https://habr.com/ru/post/975139/


All Articles