aaemnnosttv / wp-cli-login-command

Log in to WordPress with secure passwordless magic links.
https://aaemnnost.tv/wp-cli-commands/login/
MIT License
292 stars 47 forks source link

Determining the cause of 404s #54

Closed jcatello closed 2 years ago

jcatello commented 2 years ago

We've implemented wp-cli-login-command on several hundred sites to test and for most its great! But we are seeing also a fair amount of cases where the generated link brings you to a 404 page, we are unable to determine the cause, some of the sites are just fresh installs of WordPress.

Running the latest package:

# wp package install aaemnnosttv/wp-cli-login-command
Installing package aaemnnosttv/wp-cli-login-command (dev-main || dev-master || dev-trunk)
Updating /root/.wp-cli/packages/composer.json to require the package...
Using Composer to install the package...
---
Loading composer repositories with package information
Found 146 package versions referenced in your dependency graph. 31 (21%) were optimized away.
Updating dependencies
Generating rules
Resolving dependencies through SAT
Looking at all rules.
Something's changed, looking at all rules again (pass #1)

Dependency resolution completed in 0.000 seconds
Analyzed 115 packages to resolve dependencies
Analyzed 119 rules to resolve dependencies
Nothing to modify in lock file
Installing dependencies from lock file
Nothing to install, update or remove
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
---
Success: Package installed.
# wp login install --mu --yes
Success: Companion plugin installed.
# wp login create bigscoots
Success: Magic login link created!
-----------------------------------------------------------------
https://SOMEDOMAIN.com/3bfa7aec/0d6f91-07fe7213-ab178ce1
-----------------------------------------------------------------
# curl -IL https://SOMEDOMAIN.com/3bfa7aec/0d6f91-07fe7213-ab178ce1
HTTP/1.1 404 Not Found

WP Core 5.9.3

Temp disabled all plugins and set to a default twentytwentytwo

Outside of trying to rule out problematic themes/plugins what other ways do we have to troubleshoot whats causing these 404s. The sites affected are completely random, it could be one site out of 10 on the same server using same configurations.

Just looking to get some possibilities / ideas on how to troubleshoot this further, thanks!

aaemnnosttv commented 2 years ago

Hey there, that's odd.

Is the 404 that's coming back from WP or the web server? The command doesn't return a 404 itself so this would indicate that the request isn't hitting WP for whatever reason, the server plugin isn't running (I see you installed it as mu, so should be fine), or the request isn't meeting the criteria of an eligible request that it should handle.

Is there any special proxying/handling of the request between web server and WP by chance?

jcatello commented 2 years ago

Its WordPress throwing the 404 not the server, if you browse to it you see the actual 404 generated by WordPress.

The site is behind Cloudflare but isn't doing page caching which could potentially interfere just the default static caching, but just about all sites we host are behind Cloudflare as well.

No special handling in anyway, the nginx configuration used is the same for all sites.

redtux commented 2 years ago

Hi, thank you for this plugin! I love the concept and the great CLI integration.

Unfortunately, I am experiencing the same issue - no matter whether installed as normal plugin or as must-use.

My Env

I am using bedrock and nginx with web as docroot and web/wp as wp path. My setup does not differ much from #48.

Plugin List

+---------------------+----------+--------+---------+
| name                | status   | update | version |
+---------------------+----------+--------+---------+
| wp-stage-switcher   | active   | none   | 2.2.0   |
| bedrock-autoloader  | must-use | none   | 1.0.3   |
| wp-cli-login-server | must-use | none   | 1.3     |
+---------------------+----------+--------+---------+
jcatello commented 2 years ago

The issue with us was the try_files directive we were using in the location block.

You might find several variations but using:

try_files $uri $uri/ /index.php?$args;

is what fixed 404's for us

adrianratajczak commented 2 years ago

@jcatello I noticed that I have 404 error on few sites. Where I can change try_files $uri $uri/ /index.php?$args; ?

jcatello commented 2 years ago

Depends, do you use nginx? I would speak with your host if you truly don't know.

adrianratajczak commented 2 years ago

On host where 404 appears I am using LiteSpeed

jcatello commented 2 years ago

Then my suggestion doesn't apply for you since it is only meant for nginx, not litespeed, but I would try using a blank .htaccess file with just the default wordpress rewrites:

https://wordpress.org/support/article/htaccess/#basic-wp

and see if the issue persists.

adrianratajczak commented 2 years ago

@jcatello I tried on fresh install where 404 appears with default .htaccess file. Here is my access log from host [08/Jul/2022:16:25:09 +0200] "GET /aleks/6cb5423d/4d7e80-19a1e2c7-e4fc9945f9 HTTP/2" 404 1238 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36"

Of course, a few other installations on the same host with the same settings (shared hosting) are working with a wp login like a charm.

jcatello commented 2 years ago

What's the domain? Do all the sites that throw a 404 use a subfolder?

redtux commented 2 years ago

The plugin is really great. No idea what was wrong with my setup, but everything is working fine now and I want to use the opportunity to send you a big thank you. πŸ™ Keep up the good work. πŸ‘πŸŽ‰