0

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?

Ieuan
  • 111
  • 4
  • Upstream server on 9000? Script exists at defined location? Check here, too https://serverfault.com/a/948909/92023 – B. Shea Feb 23 '20 at 17:13
  • For a start, you shouldn't use `$1`, use a named capture instead. See [this document](http://nginx.org/en/docs/http/server_names.html#regex_names). – Richard Smith Feb 23 '20 at 17:21
  • Think he's also defining FPM as upstream server when in fact nothing is listening (or he doesn't show it above) - https://serverfault.com/a/546363/92023 – B. Shea Feb 23 '20 at 17:29
  • @bshea The upstream is weird because it's through docker, but it does connect fine. I have an exact copy of this config minus the $1 running right now. I found that first link as well but both ends have access to the same directory/directories – Ieuan Feb 23 '20 at 18:08
  • @RichardSmith I will give that a shot, thanks – Ieuan Feb 23 '20 at 18:10
  • @leuan - Yep.. my guess is/was that docker is running an upstream server listener, but since I don't see it above I wanted to mention as possible problem since config uses `fastcgi_pass php_php73-fpm:9000;` as the "pass" directive.. – B. Shea Feb 24 '20 at 16:37

0 Answers0