我正在设置Laravel 4运行在portal.example.com
上而不是example.com/admin
上。登录很好,但是当我尝试在Nova中添加一个条目时,请求会用一个错误来响应:
请求网址:https://portal.example.com/nova-api/users?editing=true&editMode=create
状态代码:422
答复:{"message":"validation.min.string","errors":{"password":["validation.min.string"]}}
当我试图编辑一个项目时,会发生类似的错误:
请求网址:https://portal.example.com/nova-api/companies/2?viaResource=&viaResourceId=&viaRelationship=&editing=true&editMode=update
状态代码:422
答复:{"message":"validation.required","errors":{"package":["validation.required"]}}
当我尝试删除一个项目时,会发生一个不同的错误:
请求网址:https://portal.example.com/nova-api/companies?search=&filters=W10%3D&trashed=&resources[]=2
状态代码:500
laravel.log:[2022-08-03 08:17:21] production.ERROR: count(): Argument #1 ($value) must be of type Countable|array, null given {"userId":1,"exception":"[object] (TypeError(code: 0): count(): Argument #1 ($value) must be of type Countable|array, null given at /home/forge/example.com/vendor/laravel/nova/src/Http/Requests/DeleteResourceRequest.php:48)
中的错误
错误消息导致了这个GitHub问题,其中线程启动程序确定“问题是Nginx的错误配置,查询字符串没有传递给Laravel”。这是我的Nginx配置:
include forge-conf/example.com/before/*;
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_tokens off;
server_name portal.example.com;
root /home/forge/example.com/public;
# forge SSL stuff removed
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/example.com/server/*;
location / {
try_files $uri $uri/ /index.php?query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/example.com-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/example.com/after/*;
请注意,有另一个Nginx配置为我的主Laravel应用。
这是Laravel的.env文件:
APP_ENV=production
APP_DEBUG=false
APP_KEY=base64:abcd
APP_URL=https://example.com.com
NOVA_APP_NAME=example
NOVA_DOMAIN_NAME=portal.example.com
NOVA_LICENSE_KEY=abcd
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=example
DB_USERNAME=forge
DB_PASSWORD="abcd"
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=cookie
SESSION_LIFETIME=120
MEMCACHED_HOST=memcached
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=smtp.mandrillapp.com
MAIL_PORT=587
MAIL_USERNAME=example
MAIL_PASSWORD=abcd
MAIL_FROM_ADDRESS="info@example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
SCOUT_DRIVER=meilisearch
SCOUT_QUEUE=true
MEILISEARCH_HOST=http://127.0.0.1:7700
MEILISEARCH_KEY=abcd
SANCTUM_STATEFUL_DOMAINS=example.com
SPA_URL=https://example.com
SESSION_DOMAIN=portal.example.com
请帮我找出我错过了什么。对我来说,似乎所有查询字符串都传递给Nova,但考虑到我并不真正理解Nginx,我认为很可能会在那里找到问题。谢谢!
发布于 2022-08-31 17:07:21
您可以通过更新config/nova.php
文件在子域上运行nova,如下所示:
/*
|--------------------------------------------------------------------------
| Nova Domain Name
|--------------------------------------------------------------------------
|
| This value is the "domain name" associated with your application. This
| can be used to prevent Nova's internal routes from being registered
| on subdomains which do not need access to your admin application.
|
*/
'domain' => env('NOVA_DOMAIN_NAME', null),
您可以在这里替换域值,或者定义一个env变量,它的值就是您的子域。
另一方面,您需要配置Apache/Nginx来处理新的子域:
<VirtualHost *:80>
ServerName admin.mysite.localhost
ServerAlias admin.mysite.localhost
ServerAdmin admin@mysite.localhost
...
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "${SRVROOT}/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI}
BrowserMatch "MSIE [2-5]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# Per-Server Logging:
CustomLog "${SRVROOT}/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
我希望这能帮上忙。
https://stackoverflow.com/questions/73218718
复制相似问题