Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5058

Nginx allow specific file extensions for the root folder

$
0
0

I have a site running on php Modx Revo engine and served by nginx. I have a lot of files in the root folder and now they are accessible from the internet with mysite.com/README.md urls. I want to deny access to all of them except files with extensions I want to manually specify (json, js, html and png);Here is my nginx config

server {    listen 443 ssl;    server_name mysite.com;    access_log off;    root /var/www/mysite.com;    index index.php;    #ssl stuff    location / {        root /var/www/mysite.com;        if (!-e $request_filename) {                rewrite ^/(.*)$ /index.php?q=$1 last;        }    }    location ~ \.php$ {        try_files $uri =404;        fastcgi_split_path_info ^(.+\.php)(.*)$;        fastcgi_pass   unix:/run/php/php7.2-fpm.sock;        fastcgi_index  index.php;        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;        include fastcgi_params;        fastcgi_ignore_client_abort on;        fastcgi_param  SERVER_NAME $http_host;        fastcgi_buffer_size 128k;        fastcgi_buffers 4 128k;    }    location ~*^.+\.(jpg|jpeg|gif|png|css|zip|pdf|js|ico|html) {        root   /var/www/mysite.com/;        access_log off;        expires max;    }}

I need help with new nginx rule to deny access to all files in the root folder (site.com/cronjob.sh, site.com/anyfile.anyext) except files with .json, .js, .html, .png extensions (site.com/data.json, site.com/pic.png)


Viewing all articles
Browse latest Browse all 5058

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>