Reputation: 85
Im trying to upload both Laravel 6.2 as a backend And Nuxt 2.11 as frontend (universal mode) into a server but after upload every routes returns laravel 404, Im am also using nginx reverse proxy (production mode)
Using this laravel-nuxt package https://github.com/cretueusebiu/laravel-nuxt
Upload Steps
1- upload backend files and folders ( app,bootstrap,client,config,database,routes,storage,vendor,package.json and lock,composer.json and lock)
2-upload frontend files and folders(.nuxt, and everything insdie my client folder)
3-In my server Ive added a new line at the end of my nginx.conf include /etc/nginx/sites-enabled/*.conf;
4- then in /etc/nginx/sites-enabled I have default.conf with the following content
server {
# server on port 80 (default http port)
listen 80;
server_name rabter.com;
# proxy for frontend
location / {
# nuxt server url
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
# proxy for api
location /api/* {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
# laravel server url
proxy_pass http://localhost:8000;
proxy_redirect off;
}
}
Enable my Server Blocks and Restart Nginx ln -s /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/
5- Ill setup pm2 server so I run pm2 start Laravel-nuxt to start listening to port 3000 ( lunching nuxt)
At this point I access my site which returns 404 on all routes no exception I also came across this https://github.com/iliyaZelenko/laravel-nuxt/issues/1#issuecomment-491484474 which I think it essentially what I want to do even tried the nginx code but didnt work
I have 0 routes in my web.php and all the routes are in api.php.Also this project works fine on localhost both dev and prod mode but when I move to the server its all 404.
Upvotes: 0
Views: 1502
Reputation: 85
the right configuration file for ssl The http Configuration File
server {
listen your-server-ip:80;
server_name example.com;
return 301 https://www.example.com$request_uri;
}
The ssl configuration file
server {
listen your-server-ip:443 ssl;
server_name example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen your-server-ip:443 ssl;
server_name www.example.com;
ssl_certificate /etc/pki/tls/certs/example.com.bundle;
ssl_certificate_key /etc/pki/tls/private/example.com.key;
root /home/example/core/public/;
index index.php;
access_log /var/log/nginx/example.com.bytes bytes;
access_log /var/log/nginx/example.com.log combined;
error_log /var/log/nginx/example.com.error.log error;
location / {
proxy_set_header Connection "keep-alive";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_http_version 1.1;
proxy_pass https://your-server-ip:3000$uri;
proxy_intercept_errors on;# In order to use error_page directive this needs to be on
error_page 404 = @php;
}
location @php {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass your-server-ip:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
}
Keep in mind my port was 3000
yours might be different
fastcgi_pass can be poiting to a sock too but I directly added it
fastcgi_pass port is set to 9000 in my case Yours can be different
with those being said , We are redirecting 80 and 433 without www to www and then doing a reverse proxy , if the reverse proxy is 404 we try @php and at bottom we are using php-fpm to run our php code
I almost spent 2 weeks learning nginx and writing different configuration till I cameup with this one
Upvotes: 0