By Martyn Drake
I have defined the following block for PHP:
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
fastcgi_intercept_errors on;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Whenever I attempt to define a location block to prevent access to wp-admin or wp-login.php, the PHP file is downloaded:
Root location:
location / {
try_files $uri $uri/ /index.php?$args;
}
and directly underneath that:
location ~ ^/(wp-admin|wp-login\.php) {
try_files $uri $uri/ /index.php?$args;
allow xxx.xxx.xxx.xxx;
allow xxx.xxx.xxx.xxx;
deny all;
}
I can’t for the life of me figure out why it’s bypassing PHP and downloading.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello mbdrake76 !
Are you using a .htaccess file and if so, do you have the default WordPress rewrite rules in it?
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Looking forward to your reply Alex
Hello,
You could try_files part from the deny block, I think that this should fix the issue for you.
So it should look something like:
location ~ ^/(wp-admin|wp-login\.php) {
allow 1.2.3.4;
deny all;
}
Hope that this helps! Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.