Nginx with a subdirectory site that does not match the ends of the URL

When I try to use the larvel PHP framework, I try to put it in the /home/usr/proj/laravel , but as we know the public html laravel is resolved in /home/usr/proj/laravel/public , so my problem is how to make the nginx installation so that when I access using mysite.com/laravel/ or mysite.com/laravel , we are actually redirected to the location laravel/public/index.php .

In addition, it seems that there is a nignx rule proposed by an official laravel to make the URL look pretty.

 location / { try_files $uri $uri/ /index.php?$query_string; } 

How can I use this in my case?


UPDATE

The following code seems to work for me (but give me the NotFoundHttpException error in the line RouteCollection.php 145: possibly caused by the configuration of my router)

  location /laravel{ root /home/usr/proj/laravel/public; index index.php index.html; try_files $uri $uri/ /laravel/public/index.php?$query_string; } 
+5
source share
1 answer

As for your update, I think you should keep your original try_files syntax:

 try_files $uri $uri/ /index.php?$query_string; 

since the location is set to /laravel and the root is in the public folder. The way it is currently written ends with a search for the file /home/usr/proj/laravel/public/public/index.php on disk.

You should also check how to configure the application url to contain the /location part of the url. I'm not quite sure how Laravel 5 is configured, as my experience is with Laravel 4.

0
source

Source: https://habr.com/ru/post/1239544/


All Articles