We've got nginx running on Ubuntu Trusty. It serves several websites over https, running on one ip address.
Randomly, although it seems slightly related to work load, sometimes single requests turn up on the wrong vhost. This leads to requests on lustrum.thalia.nu being served by thalia.nu and vice-versa. This then gives nasty error pages as users suddenly end up on a different web site. When you press F5, users then end up on the original target again.
It does not seem browser or operating system related. It's been confirmed to happen on Firefox (Linux, Windows, Mac), Edge (Windows) and Chrome (Linux, Windows, Android) and Safari (iOS).
The issue appears to occur more frequently when the system is put under load, suggesting some sort of race condition.
lustrum.thalia.nu
server {
server_name lustrum.thalia.nu;
listen 443 ssl;
ssl on;
ssl_certificate /etc/nginx/certs/lustrum.thalia.nu.crt;
ssl_certificate_key /etc/nginx/certs/lustrum.thalia.nu.key;
add_header Strict-Transport-Security "max-age=63072000; preload";
root /var/www/thalia-lustrum/public_html;
location / {
index index.php;
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ [^/]\.php(/|$) {
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:/var/run/php5-fpm-thalia-lustrum.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /public_html$fastcgi_script_name;
}
}
thalia.nu
server {
server_name thalia.nu;
listen 443 ssl;
ssl on;
ssl_certificate /etc/nginx/certs/www.thalia.nu.crt;
ssl_certificate_key /etc/nginx/certs/www.thalia.nu.key;
add_header Strict-Transport-Security "max-age=63072000; preload";
root /var/www/thalia/public_html;
location / {
try_files $uri $uri/ /index.php/$request_uri;
index index.php index.html index.htm;
}
location ~ \.php($|/) {
include /etc/nginx/fastcgi_params;
set $script $uri;
set $path_info "";
if ($uri ~ "^(.+\.php)(/.+)") {
set $script $1;
set $path_info $2;
}
fastcgi_read_timeout 120;
fastcgi_pass unix:/var/run/php5-fpm-thalia-www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /public_html$fastcgi_script_name;
}
}
As you can see, we're running different PHP5-FPM pools for these two domains. These pools are chrooted to different folders and run as different users. PHP-FPM's configuration are otherwise fairly standard as far as I can tell.
We've tried both nginx 1.4.6-ubuntu3 and nginx 1.8.0-1+trusty.
Log telemetry
266.266.266.266 - - [25/Nov/2015:09:24:40 +0100] "GET /committees/175 HTTP/1.1" 302 5 "https://thalia.nu/committees" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0" Host: "thalia.nu" Location: "https://thalia.nu/index.php//committees/wp-admin/setup-config.php"
In this line you can see that the request for the page /committees suddenly gets redirected to wp-admin. This appears that the request for /committees got handled by the thalia-lustrum PHP-fpm pool...
DNS zone file
We don't see how this can possibly be relevant, but...
;; MX Records
thalia.nu. 300 IN MX 20 relay.transip.nl.
thalia.nu. 300 IN MX 10 ivo.thalia.nu.
;; TXT Records
thalia.nu. 300 IN TXT "v=spf1 a mx a:mulgore.hexon-is.nl a:moonray.hexon-is.nl a:fred.thalia.nu a:ivo.thalia.nu ~all"
;; SPF Records (Sender Policy Framework)
thalia.nu. 300 IN SPF "v=spf1 a mx a:mulgore.hexon-is.nl a:moonray.hexon-is.nl a:fred.thalia.nu a:ivo.thalia.nu ~all"
;; CNAME Records
lustrum.thalia.nu. 300 IN CNAME thalia.nu.
;; A Records (IPv4 addresses)
thalia.nu. 300 IN A 131.174.31.8
www.thalia.nu. 300 IN A 131.174.31.8
ivo.thalia.nu. 300 IN A 131.174.31.8
Host:http header (Name based virtual hosting) – Fredi Nov 24 '15 at 11:03Host:http header and user agent? See here for how: http://serverfault.com/questions/636790/nginx-log-complete-request-response-with-all-headers. Actually i tried makeing some requests to your websites but culdn't reproduce your problem. What client are you using for reproducing this? – Fredi Nov 24 '15 at 13:15lustrum.thalia.nu. 300 IN CNAME thalia.nu. thalia.nu. 300 IN A 131.174.31.8– Thom Wiggers Nov 24 '15 at 16:45Hostheader logged. If Nginx makes a mistake in vhost selection, you'd think the host header is also wrong. – Halfgaar Nov 25 '15 at 08:16config.phpnot found. – Halfgaar Nov 25 '15 at 08:26ifblocks in allserverblocks, and I can still reproduce it. – Thom Wiggers Nov 25 '15 at 18:38Third party libraries not installed. Make sure that composer has required libraries in the concrete/ directory.message multiple times onlustrum.thalia.nu(using code 200 even though there was an error). Andthalia.nusometimes redirects tohttps://thalia.nu/wp-admin/setup-config.php. But I don't see any indication that requests are directed to the wrong vhost. – kasperd Nov 25 '15 at 19:10wp-adminis code from thelustrum.thalia.nuchroot, while the Composer error is code from thethalia.nuchroot... Something is going wrong there. – Thom Wiggers Nov 25 '15 at 19:14