I have some content in WordPress for pages with static content or Marketing landing pages. We decided to go on this way because of reasons…
So for doing that I have the configuration below in NGINX
server {
server_name mydomain.com;
location / {
root /var/www/webapp;
index index.html index.htm;
try_files $uri /index.html;
location ~* \.(eot|ttf|woff)$ {
add_header Access-Control-Allow-Origin *;
}
access_log /var/log/nginx/webapp.access.log;
error_log /var/log/nginx/webapp.error.log;
}
# Alias for discover when is WordPress related content
location /discover/ {
index index.html index.htm index.php;
root /var/www/wordpress;
try_files $uri $uri/ /index.php$is_args$args;
access_log /var/log/nginx/wordpress.access.log;
error_log /var/log/nginx/wordpress.error.log;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
Sadly this is not working, it's always rendering or try to render the react app even when I go to mydomain.com/discover/ or /discover/something
I configured WordPress URL to mydomain.com/discover in the WP Configuration.
The error for this configuration is
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client:
If I move the PHP extension file configuration outside of /discover I remove the FastCGI Primary script unknown error but I still NGINX resolve everything to the react app.
Some I'm quite new with NGINX I've been using Apache my whole so might be a really noob error, but it's killing already.
I tried moving things around even as default but similar errors.
Any help or guide will help me.
Best Answer
To access a path like
/var/www/wordpress/
with a URI like/discover/
, you will need to usealias
rather thanroot
. See this document for details.For example:
The
location
value and thealias
value should either both end with a/
or neither end with a/
.Note that when using
alias
,$request_filename
should be used to find the path to the filename.There is a long standing bug related to using
alias
andtry_files
together, which is why these blocks use theif
directive instead. Note this caution on the use of theif
directive.