We just started running nginx a few weeks ago and need to block access to certain files/location. e.g.:
/wordpress/wp-admin/
/wp-admin/
/test/wp-admin/
/hudson/login
/phpmyadmin/index.php
/mysql/index.php
/myadmin/index.php
/wp-cron.php
/xmlrpc.php
In general we would like to block any file request except /index.php and also any location such as /wp-admin/, /test/wp-admin/, /wordpress/wp-admin/, etc. These files/locations don't exist, so anybody accessing them is trying to hack/abuse the system.
In Apache we would use .htaccess
to block such. How do block in Nginx?
Current Conf
server {
listen 80;
root /home/public_html;
index index.php;
server_name domain.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}
location
is necessary here? if the URI's don't exist, nginx will, by default, send a response with the404
code and HTML with<h1>404 not found</h1>
etc, I would have thought thats as good as you can do? – the_velour_fog May 06 '17 at 08:05app/routes.php
file so the app has to determine if the url is valid. yes its possible to write a location block that matches those wordpress urls and get nginx to check those first and then send all remaining requests to laravel. – the_velour_fog May 06 '17 at 11:37