Laravel-vue SPA Nginx deployment problem - api routes not found Deployed an app to DO. App loading, Images from app/storage OK. However ip-address/api/* returns 404. Same with postman. Everything worked fine on Ubuntu Homestead. I'm a newbie and my first instinct is that it is an Nginx configuration issue.
Postman log:
POST http://153.xx.xxx.188/api/auth/login
404 Not Found
....
Nginx access.log:
67.149.236.101 - - [12/Feb/2020:22:05:21 +0000] "POST /api/auth/login HTTP/1.1" 404 209 "http://153.xx.xxx.188/login" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...
route:list
+--------+----------+-------------------------+------+---------------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------------------------+------+---------------------------------------------------+--------------+
| | GET|HEAD | api/areas | | App\Http\Controllers\AreaController@index | api,jwt.auth |
| | GET|HEAD | api/areas/loci | | App\Http\Controllers\AreaController@loci | api,jwt.auth |
| | POST | api/auth/login | | App\Http\Controllers\AuthController@login | api |
| | POST | api/auth/logout | | App\Http\Controllers\AuthController@logout | api,auth:api |
| | POST | api/auth/me | | App\Http\Controllers\AuthController@me | api,auth:api |
| | POST | api/auth/refresh | | App\Http\Controllers\AuthController@refresh | api,auth:api |
| | GET|HEAD | api/loci | | App\Http\Controllers\LocusController@index | api,jwt.auth |
| | POST | api/loci/store | | App\Http\Controllers\LocusController@store | api,jwt.auth |
| | PUT | api/loci/store | | App\Http\Controllers\LocusController@store | api,jwt.auth |
....
| | GET|HEAD | {any} | | Closure | web |
+--------+----------+-------------------------+------+---------------------------------------------------+--------------+
deployed by following this guide: https://gist.github.com/vicgonvt/cd0431a5cdc043ebab7f4954f7b4d471
PLEASE HELP!!!
make sure that your app is inside /var/www/html/[YOUR PROJECT] and your nginx config is
server {
listen 80;
root /var/www/html/[YOUR PROJECT]/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name [YOUR IP ADDRESS];
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
and then repeat the permission then test the nginx config
sudo nginx -t
and then restart the nginx server
sudo service nginx restart
Thank you for writing!
My server's /etc/nginx/sites-available/sub.dom.com was identical to the template you attached.
I did re-run the whole thing with the same results - app loads, storage accessible, but apis not found. As you can see from nginx access.log for some reason my POST /api/auth/login HTTP/1.1" returns 404 209 "http://153.xx.xxx.188/login", truncating the /api/auth/login - This is probably the key to figuring out the failure. Again, these routes, all present at server as the attached list shows, do work on my local Homestead.
Thanks again!
server {
listen 80;
server_name [ IP | DOMAIN];
root /home/yd/www/laravel/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# Rewrite
if (!-d $request_filename) {
rewrite ^/(.+)/$ / permanent;
}
charset utf-8;
# PHP FPM.
location ~* \.php$ {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# .htaccess.
location ~ /\.ht {
deny all;
}
}
Thank you so much - now it's working!!!
I guess I should have copied from Homestead...
What is the mysterious SCRIPT_FILENAME?
Can you recommend an easy intro to Nginx for first time deployers that will explain all this?
Thanks again and again!
Thank you so much for your help.
Please sign in or create an account to participate in this conversation.