I've set up a new Laravel 5.7 site on a VPS. I had previously run the site locally using valet with no issues. However, now when I navigate to my dashboard route using https://mysite.mydomain.net/dashboard, I'm getting a 403 error returned by nginx (there's no laravel errors, so I'm assuming it never gets to laravel at all).
Other paths that hit other routes with a similar structure don't seem to be affected.
I've tried running php artisan route:clear to make sure it's not hitting an older cached routing.
The route is simple:
Route::get('/dashboard', function () {
return "yo";
})->name('dashboard'); // returns 403
Almost exactly the same route returns the expected result with no issue:
Route::get('/test', function() {
return "test";
})->name('test'); // returns "test"
Here's the nginx config:
server {
# Log files for Debugging
access_log /var/log/nginx/laravel-access.log;
error_log /var/log/nginx/laravel-error.log;
# Webroot Directory for Laravel project
root /var/www/mysite/public;
index index.php index.html index.htm;
# Your Domain Name
server_name mysite.mydomain.net;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# PHP-FPM Configuration Nginx
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.mydomain.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.mydomain.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = mysite.mydomain.net) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80 ipv6only=on;
server_name mysite.mydomain.net;
return 404; # managed by Certbot
}
Does laravel authentication throw an nginx 403 error? I would expect it to at least show a laravel error message-- and besides, there's no middleware on this route. What could be going on?
The nginx error log shows:
2018/10/30 20:46:48 [error] 19626#19626: *2201 directory index of "/var/www/mysite/public/dashboard/" is forbidden, client: 98.146.255.247, server: mysite.mydomain.net, request: "GET /dashboard/ HTTP/1.1", host: "rem$
try_files $uri $uri/ /index.php?$query_string;doesn't get to call the php and nginx tries to serve content in $uri/try_files $uri /index.php?$query_string;But it's a much better idea not to have your app a site root to avoid those confusionspublic/dashboardthat holds my mixed down css / js etc. assets.$uri/fixed the issue. Please make that your answer and I'll accept it. Thanks!