我正在尝试设置一个开发堆栈,我可以在里面简单地创建一个新目录,并通过 nginx 将其作为子域访问。我遇到了臭名昭著的“主脚本未知”问题,我认为这与通配符有关,因为这个确切的配置没有它在另一个项目中运行良好。
这是我的 nginx 配置:
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;
}
}
这是我的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
当我尝试(显式)访问 index.php 时,nginx 错误日志显示
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"
只需访问子域名即可显示GET /
我尝试过各种方法,比如在 index.php 前面和 nginx 配置中的目录后面添加或删除正斜杠,但似乎没有帮助。请注意,我已删除了一些信息,这些信息都正确显示在我的配置文件和日志文件中。
我的配置有什么明显错误吗?