Answer the question
In order to leave comments, you need to log in
How to allow only certain URLs in nginx?
I need to restrict nginx to open only certain URLs with a regex, in JavaScript it looks like this
/^(\/[\w_-]*)+(.(php|js|css|jpg|png))?(\?([a-z][\w\[\]]*=[\w_-]*&?)*)?$/
^(/файлнейм)+(\.расширение)?(\?(ключ=значение&?)*)?$
server {
listen 80;
root /home/ubuntu/site;
location ~ \.php$ {
try_files $uri = 404;
include fastcgi_params;
#fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location / {
try_files $uri /index.php?$query_string;
}
}
Answer the question
In order to leave comments, you need to log in
more or less like this
location / {
deny all; # deny by default
location ~* \.(php|js|css|jpg|png)$ {
allow all;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question