English 中文(简体)
Unusual NGINX Wordpress Configuration Issues (Headless Wordpress + Static Site Front-End on Single Domain)
原标题:

I have a very particular use case where I use Wordpress as a CMS backend (mostly in a headless configuration), with the exception of certain URLs that I want the usual NGNIX/Wordpress config to apply. Specifically:

Most url requests to the NGINX root should serve static HTML files from a subdirectory. I have this identified in this location block within the server block of my virtual hosts file:

location / {
    root /var/www/html/node/website.com/_build;
    index index.html;

    try_files $uri $uri.html $uri/ /404/index.html;
}

But all Wordpress specific files (i.e. those behind a /wp-* URL) should still be served by Wordpress. Eventually, a few specific URLs (i.e. /shop, /my-account) should also be served by Wordpress and not the static html files, but I can work on that later. I currently have the WP-specific location identified as:

location ~* /wp- {
    index index.php;
    try_files $uri $uri/ /index.php?$query_string;

    location ~ .php$ {
        root /var/www/html/php/website.com;
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
    }
}

This works partially. website.com/wp-json works correctly. Most URL endpoints are served from the _build subdirectory, assuming a relevant HTML file exists. But, website.com/wp-admin and website.com/wp-login.php auto-download the relevant PHP files instead of processing them.

This tells me there is an issue with passing the index.php files to php-fpm, but I can t figure out where the break is. FWIW, I am duplicating the location ~ .php$ block in the server block as well, outside of the wp- block.

Any suggestions?

Also, if anyone has suggestions for correct configuration of specific "front-end" URLs (i.e. /shop,/my-account) to be served by Wordpress vs. the _public HTML files, that would be really helpful and awesome.

问题回答

Turns out this was a caching issue in Chrome. An incognito window load showed that my location blocks were written correctly and working. Leaving this question here in case someone has a better suggestion for what I am trying to do, or can use this as a reference.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签