1

I'm running a headless Wordpress instance and nginx is routing it to /adminon my website. On Wordpress I have the WPGraphql plugin installed and activated. GraphiQL is working and querying everything correctly, but I get a 404 page not found when clicking on the link ( https://example.com/admin/graphql ) . Instead I expect to see something in JSON format, like: {"errors":[{"message":"GraphQL Request must include at least one of those two parameters: \"query\" or \"queryId\"","extensions":{"category":"request"}}],"extensions":{"debug":[]}}

I suspect this has something to do with my routing in nginx but I haven't been able to figure this one out.

This is my nginx configuration for the route where I'm accessing the Wordpress admin.

location /admin {    
   ​add_header X-Frame-Options SAMEORIGIN;    ​add_header Strict-Transport-Security "max- 
   age=31536000";    
   ​add_header X-Content-Type-Options nosniff;    ​
   add_header X-XSS-Protection "1; mode=block";    
   ​alias /home/lmraza98/wordpress/; ​
   try_files $uri $uri/ /index.php?$args;    ​
   include  /etc/nginx/mime.types;

   ​location ~ \.php$ {
      ​include snippets/fastcgi-php.conf;
      ​fastcgi_param SCRIPT_FILENAME $request_filename;
      ​fastcgi_pass unix:/run/php/php7.4-fpm.sock;    ​
   }

   ​location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
      ​expires max;
      ​log_not_found off;    
   ​}  
​}

Lucas Raza
  • 499
  • 1
  • 4
  • 13
  • Can you tell if it is Nginx's 404 or WordPress's? – Chris Haas Jul 20 '21 at 17:18
  • @ChrisHaas Yeah it is Nginx's 404 page – Lucas Raza Jul 20 '21 at 18:45
  • Is the `admin` route the root of the WordPress install? Or is that a custom route? Can you try `root` instead of `alias`, too? They are very similar and I know that the latter sometimes doesn't act how people expect it to, but I think that is usually only in a regex context. – Chris Haas Jul 20 '21 at 18:50
  • @ChrisHaas correct , the admin route is the root of the WordPress install. I just tried with ```root``` instead of alias and nginx ended up displaying a 404 for ```/admin``` but with ```alias``` WordPress works – Lucas Raza Jul 20 '21 at 19:01
  • 2
    Can you try bypassing the permalinks in your browser by going to `https://example.com/admin/index.php?graphql` – Chris Haas Jul 20 '21 at 19:46
  • So if that works, you might just need to flush your permalinks – Chris Haas Jul 20 '21 at 20:10
  • Do you know how this would be done? Still kinda confused with permalinks – Lucas Raza Jul 20 '21 at 22:01
  • If you are using the WP CLI, which I totally recommend, it is just `wp rewrite flush`, otherwise, just visit the normal WP admin area, settings permalinks, and hit save. Regardless of changing anything, it will flush the permalinks. – Chris Haas Jul 21 '21 at 03:25

0 Answers0