我正在尝试创建一个Nginx配置,它对所有以/craft
开头的路由使用PHP-FPM,对所有其他路由(应该为Next.js应用程序提供服务)使用另一个代理:
# Next.js upstream config
upstream nextjs {
server host.docker.internal:3000;
}
# Proxy cache
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=7d use_temp_path=off;
server {
listen 80;
listen [::]:80;
server_name localhost;
# Document root
root /var/www/html/web;
index index.php;
# Logs
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log warn;
# Craft CMS
location /craft {
include "/etc/nginx/sites-shared/static-files.conf";
try_files $uri $uri/ /index.php?$query_string;
}
location ~ [^/]\.php(/|$) {
try_files $uri $uri/ /index.php?$query_string;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
# Next.js's built assets
# Browser cache - max cache headers from Next.js as build id in url
# Server cache - valid forever (cleared after cache "inactive" period)
location /_next/static {
proxy_cache STATIC;
proxy_pass http://nextjs;
}
# Next.js's static assets
# Browser cache - "no-cache" headers from Next.js as no build id in url
# Server cache - refresh regularly in case of changes
location /static {
proxy_cache STATIC;
proxy_ignore_headers Cache-Control;
proxy_cache_valid 60m;
proxy_pass http://nextjs;
}
# Next.js app
location / {
proxy_pass http://nextjs;
}
}
安装工作正常(在https://foobar.dev:8843/craft/index.php?p=admin/install上运行),但是一旦我被重定向到https://foobar.dev:8843/craft/admin/dashboard,我就会得到以下错误:
2021/02/11 11:39:03 [error] 32#32: *1 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 172.20.0.1, server: localhost, request: "GET /craft/admin/dashboard HTTP/2.0", host: "foobar.dev:8843", referrer: "https://foobar.dev:8843/craft/index.php?p=admin/install"
这就是我的/var/www/html
目录结构
.
└── /
├── config
├── modules
├── storage
├── templates
├── vendor
├── web/
│ ├── app/
│ │ └── index.php
│ └── craft/
│ ├── cpresources
│ └── index.php
├── .env
├── composer.json
├── composer.lock
└── craft
https://foobar.dev:8843/app/
也运行得很好,但似乎URL重写不起作用,而且我不理解错误消息中提及的and重定向循环。
发布于 2021-02-11 23:52:12
它在这种配置下工作得很好:
# Craft CMS
location /craft {
try_files $uri $uri/ /craft/index.php?$query_string;
}
location ~ [^/]\.php(/|$) {
# 404
try_files $fastcgi_script_name =404;
# default fastcgi_params
include fastcgi_params;
# fastcgi settings
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
# fastcgi params
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
}
https://stackoverflow.com/questions/66154133
复制相似问题