NGINX Access Log by Location
This is happening because the location that ultimately ends up handling your requests is location ~ \.php$
, which inherits its log configuration from the server context. Assuming that the yoast seo sitemap belongs to app1, you'll want a config something like this:
# Use an upstream to future changes easier
upstream _php {
server unix:/var/run/php/php7.0-fpm.sock;
}
server {
listen 80 default;
listen [::]:80;
root /var/www/html/app1;
index index.php;
server_name localhost;
access_log /var/log/nginx/app1.access.log;
error_log /var/log/nginx/app1.error.log;
# Put php directives in the server context so they can be inherited by all locations
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
# Locations that aren't logged can be left outside and shared
location ~ /\.(?!well-known) {
deny all;
access_log off;
log_not_found off;
}
location ~* \.(woff|jpg|jpeg|png|gif|ico|css|js)$ {
access_log off;
log_not_found off;
expires 365d;
}
# Everything that logs to app1 should go in here
location / {
try_files $uri $uri/ /index.php?$is_args$args;
# SECURITY : Deny all attempts to access PHP Files in the uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# PHP : pass the PHP scripts to FastCGI server defined in upstream _php
location ~ \.php$ {
fastcgi_pass _php;
}
# Yoast SEO Sitemaps
location ~ ([^/]*)sitemap-rewrite-disabled(.*).x(m|s)l$ {
## this redirects sitemap.xml to /sitemap_index.xml
rewrite ^/sitemap.xml$ /sitemap_index.xml permanent;
## this makes the XML sitemaps work
rewrite ^/([a-z]+)?-?sitemap.xsl$ /index.php?xsl=$1 last;
rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
## The following lines are optional for the premium extensions
## News SEO
rewrite ^/news-sitemap.xml$ /index.php?sitemap=wpseo_news last;
## Local SEO
rewrite ^/locations.kml$ /index.php?sitemap=wpseo_local_kml last;
rewrite ^/geo-sitemap.xml$ /index.php?sitemap=wpseo_local last;
## Video SEO
rewrite ^/video-sitemap.xsl$ /index.php?xsl=video last;
}
}
# Everything that logs to app2 should go in here
location /app2 {
try_files $uri $uri/ /app2/index.php$is_args$args;
access_log /var/log/nginx/app2.access.log;
error_log /var/log/nginx/app2.error.log;
# SECURITY : Deny all attempts to access PHP Files in the uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# PHP : pass the PHP scripts to FastCGI server defined in upstream _php
location ~ \.php$ {
fastcgi_pass _php;
}
}
}
Moving the fastcgi params into the server and using an upstream for the php server means it's not a lot to duplicate.