1

This is my nginx configuration :-

server {
      listen 80 ;
      listen [::]:80 ipv6only=on default_server;
     access_log /var/log/nginx/mywebsite.log;
     error_log /var/log/nginx/mywebsite-error.log;    


  #  server_name server_domain_or_IP;
  server_name mywebsite.com www.mywebsite.com ;

   location / {
        root /home/mywebsite/frontend;
        try_files $uri /index.html;
    }

  location /services/ {
      root /home/mywebsite/backend/public;
      try_files $uri $uri /index.php?$query_string;
    }  

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}
  • The directory /home/mywebsite/frontend contain a Reactjs build index.html. enter image description here

  • The /home/mywebsite/backend/public contain a laravel framework files. enter image description here

when i access my website using the URL (mywebsite.com/) the reactjs get loaded very will without any issue, but when i use the URL (mywebsite.com/services/) nginx return error 404.

The error got in /var/log/nginx/mywebsite-error.log :-

[error] 30346#30346: *6 open() "/usr/share/nginx/html/services" failed (2: No such file or directory)

How can i fix that ?

Q8root
  • 1,243
  • 3
  • 25
  • 48
  • Not sure that if `include snippets/fastcgi-php.conf;` is correct. What is inside the `snippets/fastcgi-php.conf;`. Did you try to config nginx with laravel itself to test. – Ted Jul 03 '20 at 01:37
  • @Ted yes when i set the root directory for the virtual server directly to larvavel folder, it worked without any issue – Q8root Jul 03 '20 at 02:04
  • Seem like problems come from the way you setting `root`. Try to put the root of laravel out of you location tag and keep root of frontend inside the location tag. Reference: https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/ – Ted Jul 03 '20 at 02:15
  • Is it a problem for you to rename the `/home/mywebsite/backend/public` folder to `/home/mywebsite/backend/services`? Than the solution would be much more simple. Is there only backend that uses PHP, frontend doesn't use it? – Ivan Shatsky Jul 03 '20 at 03:51
  • I don't see `index.php` in any of your directories. Also, you may want to look at [this answer](https://stackoverflow.com/questions/42443468/nginx-location-configuration-subfolders/42467562#42467562). – Richard Smith Jul 03 '20 at 08:01

0 Answers0