1

I am setting up Laravel Nova 4 to run on portal.example.com instead of example.com/admin. Logging in works fine, but when I try to add an item in Nova, the request responds with an error:

Request URL: https://portal.example.com/nova-api/users?editing=true&editMode=create
Status Code: 422
Response: {"message":"validation.min.string","errors":{"password":["validation.min.string"]}}

When I try to edit an item, a similar error occurs:

Request URL: https://portal.example.com/nova-api/companies/2?viaResource=&viaResourceId=&viaRelationship=&editing=true&editMode=update
Status Code: 422
Response: {"message":"validation.required","errors":{"package":["validation.required"]}}

When I try to delete an item, a different error occurs:

Request URL: https://portal.example.com/nova-api/companies?search=&filters=W10%3D&trashed=&resources[]=2
Status Code: 500
Error in 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)

The error message led me to this GitHub issue, in which the thread starter determines that "the problem was Nginx misconfiguration. The query string was not passed down to Laravel". This is my Nginx config:

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/*;

Please note that there is another Nginx config for my main Laravel app.

This is Laravel's .env file:

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

Please help me find out what I am missing. For me it looks like all query strings are passed down to Nova, but considering that I don't really understand Nginx I think it's likely that the problem is to be found there. Thank you!

wildyeast
  • 13
  • 3

1 Answers1

0

You can run nova on a subdomain by updating config/nova.php file like the following:

    /*
    |--------------------------------------------------------------------------
    | 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),

You can replace the domain value here or define an env variable which it's value is your subdomain.

On the other hand, you need to configure Apache/Nginx to handle the new subdomain:

<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>

I hope this would help.

wajdi_jurry
  • 268
  • 2
  • 9