Nginx ignores HTTP Authentication for WordPress login directory

user3046831

I am running WordPress in a subfolder of my domain for testing and development purposes on a VPS LEMP-stack. In order to password-protect the wp-login.php with an etxra layer, I used HTTP authentication for the wp-admin folder.

The problem is that the http authentication is ignored. When the wp-login.php or wp-admin-folder is called, it goes directly to the normal WordPress-login.

I installed everything from the command line in the following way:

sudo apt-get install apache2-utils

sudo htpasswd -c /var/www/bitmall/wp-admin/.htpasswd exampleuser

New password:
Re-type new password:
Adding password for user exampleuser

My Nginx configuration file looks like this:

server {
    listen   80;


    root /var/www;
    index index.php index.html index.htm;

    server_name eample.com;

    location / {
            try_files $uri $uri/ /index.html;
    }

location /bitmall/wp-admin/ {
    auth_basic "Restricted Section";
    auth_basic_user_file /var/www/bitmall/wp-admin/.htpasswd;
}

location ~ /\.ht {
    deny all;
}   

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
          root /var/www;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;

    }

}

I already tried to change the nginx configuration following this question:

location ~* (wp-login)\.php$ {
            auth_basic            "Restricted Area";
            auth_basic_user_file  /var/www/bitmall/.htpasswd;
    }

This code will call the http authentification, but the browser downloads the wp-login.php, when the credentials have been entered, instead of going to the main login screen.

Could you please advice me how to fix this?

user3046831

The problem was that the old location block does not pass the PHP configuration to the new block, so that PHP requests are not processed. The following solved this problem:

location ~* /wp-login.php {
            auth_basic "Restricted Area";
            auth_basic_user_file PATH TO .htpasswd;

            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

WordPress Multisite directory nginx config

Create a custom login functionality in WordPress for API authentication

Active Directory authentication without Login form

Nginx Reverse Proxy Websocket Authentication - HTTP 403

Wordpress XML Media Import with HTTP Authentication

Why my wordpress site asks for http authentication?

WordPress reverse proxy authentication with additional http headers

Configure NextCloud & Nginx Reverse Port Forward - Login Authentication Error

How to connect to a database using Active directory Login and MultiFactor Authentication (MFA)

Change Basic HTTP Authentication realm and login dialog message

How implement Flutter login authentication & registration using Http post

unzipper ignores empty directory

Github pages ignores a directory

Tar ignores --directory option

nginx proxy request to service with header value from an authentication http request

Nginx HTTP basic authentication with exceptions for particular IP addresses

Wordpress on Sub Directory with Nginx using Proxy Pass with No Input File error

installation failed: could not create directory in wordpress nginx on ubuntu

Nginx Wordpress Configuration, PHP file in theme directory is not passed to FastCGI

Wordpress Authentication

.Net Core SPA and React - HTTP 400 after Active Directory Login

Wordpress authentication outside wordpress

Force https to http redirect except for Wordpress /wp-admin directory

nginx ignores my site configuration

Why does Doctrine SQLite ignores authentication configuration?

wordpress social login plugin returning ERR_INVALID_REDIRECT having NGINX for hosting and load balancing

Flask: Login without authentication

Login User with Firebase Authentication

Retrofit - Login Authentication (token)