Home > OS >  How to access public folder in laravel through reactjs when I serve them in NginX?
How to access public folder in laravel through reactjs when I serve them in NginX?

Time:05-30

I'm developing a project with Reactjs and Laravel(Breeze version).

The project is dockerized and for serving, I use Nginx as the web serve. I configure it to access laravel backend by adding /api to the end of the frontend url.

every thing is fine but when I try to access the uploaded images files on public folder (in backend side ) I'v got 404 eror.

this is my nginx config file:

.
.
.
  # laravel backend
  location ~ /api {
    try_files $uri $uri/ /index.php?$query_string;
  }

  location ~ \.php$ {
    root /var/www/html/backend/public;
    try_files $uri =404;
    fastcgi_split_path_info ^(. \.php)(/. )$;
    fastcgi_pass laravel:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_hide_header X-Powered-By;
  }
.
.
.
.

I have another root in my nginx config file for my frontend :

server {

  listen 80 default_server;

  server_name _;

  server_tokens off;

  root /var/www/html/frontend;
.
.
.

CodePudding user response:

The issue was solved after spending some hours just by adding the new location for my upload folder(Inside the laravel public folder) in Nginx config file:

location /uploads/ {
  alias /var/www/html/backend/public/uploads/;
}
  • Related