I am trying to set up a dev stack where I can simply create a new directory and have it accessible as subdomain through nginx. I am running into the infamous 'primary script unknown' issue, and I think it has something to do with the wildcards as this exact config without it works fine for another project.
This is my nginx config:
server {
listen 80;
listen [::]:80;
server_name ~^(.*)\.misc\.<VMhost>\.<server>\.network$;
error_log /vmdata/services/web/logs/misc/misc.error.log;
access_log /vmdata/services/web/logs/misc/misc.access.log;
client_max_body_size 8M;
index index.php;
if (!-d /vmdata/services/web/misc/$1) {
rewrite . https://<server>.network/ redirect;
}
root /vmdata/services/web/misc/$1;
location / {
try_files $uri $uri/ index.php?$query_string =404;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass php_php73-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
This is the relevant part of my docker-compose.yml:
misc:
image: nginx-services:latest
volumes:
- /vmdata/services/web/conf.d/misc.conf:/etc/nginx/conf.d/default.conf
- /vmdata:/vmdata
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik-public"
- "traefik.backend=misc"
- "traefik.wildcard.frontend.rule=HostRegexp:{subdomain:[A-Za-z0-9-]+}.misc.<VMhost>.<server>.network"
- "traefik.wildcard.frontend.headers.isDevelopment=true"
- "traefik.frontend.rule=Host:misc.<VMhost>.<server>.network"
- "traefik.static.frontend.headers.isDevelopment=true"
- "traefik.port=80"
environment:
- NGINX_HOST=*.misc.<VMhost>.<server>.network
- NGINX_PORT=80
networks:
- common
- traefik-public
When I try to access index.php (explicitly), nginx error log shows
2020/02/23 15:31:19 [error] 6#6: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 10.0.4.238, server: ~^(.*)\.misc\.<VMhost>\.<server>\.network$, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://10.0.5.51:9000", host: "<project>.misc.<VMhost>.<server>.network"
Simply accessing the subdomain shows a GET /
I have tried various things like adding or removing forward slashes in front of index.php and after the directories in the nginx config, but it doesn't seem to be helping. Note that I have redacted some information, this all shows up correctly in both my config and log files.
Is there something obvious wrong with my config?