I am running nginx. The current setup is
main_site.local (main site) physical path: /var/www/html/test/testme/bla/main_site/public_html
main_site.local/laravel physical path: /var/www/html/test/testme/bla/main_site/public_html/laravel/public
Based on this: Config nginx for Laravel In a subfolder
I have
server {
listen 81;
#listen [::]:81 default ipv6only=on; ## listen for ipv6
root /var/www/html/test/testme/bla/main_site/public_html;
index index.php index.html index.htm;
server_name main_site.local;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ^~ /laravel {
alias /var/www/html/test/testme/bla/main_site/public_html/laravel/public;
try_files $uri $uri/ @laravel;
location ~ \.php {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
}
}
location @laravel {
rewrite /laravel/(.*)$ /laravel/index.php?/$1 last;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
when i hit main_site.local/laravel, it shows a blank page, not the laravel welcome page.
I put a die in /var/www/html/test/testme/bla/main_site/public_html/laravel/public/index.php, it doesn't execute.
Update 1
Based on this: https://mnshankar.wordpress.com/2014/03/19/nginx-config-for-hosting-multiple-projects-in-sibling-folders/
I have
server {
listen 81;
root /var/www/html/test/testme/igloo/igloosof/public_html;
index index.html index.htm index.php app.php app_dev.php;
server_name main-site.local;
charset utf-8;
location /laravel{
rewrite ^/laravel/(.*)$ /laravel/public/index.php?$1 last;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Error: NotFoundHttpException in RouteCollection.php line 161 I am accessing the default laravel home page (the welcome page)
Incase you still havn't solved this, try adding fastcgi_param SCRIPT_FILENAME
to in location->php block of your first example.
Here is how I setup-ed my location
block which is working for me perfectly:
location ^~ /facebookschedule {
alias /home/netcans/facebookschedule/public;
try_files $uri $uri/ @foobar;
location ~ \.php {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/wwww/facebookschedule/public/index.php;
}
}
location @foobar {
rewrite /facebookschedule/(.*)$ /facebookschedule/index.php?/$1 last;
}
I was also getting similar White Screen (blank page) and 404 errors related to route not found but was able to fix everything following the full Nginx Conf file example from this post:
http://shubhank.gaur.io/setup-laravel-5-in-subfolder-with-nginx/
It's maybe because about your ngnix config. in two way you can check config :
If you want to put your laravel
project in a subfolder
on a server with ngnix-ubuntu 16-php.7.2
, so here is update ngnix config :
1) your nested(subfolder) isn't inside your main folder
/var/www/main:
/var/www/nested:
then your config :
location /nested {
alias /var/www/nested/public;
try_files $uri $uri/ @nested;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
location @nested {
rewrite /nested/(.*)$ /nested/index.php?/$1 last;
}
2) your laravel-test folder (subfolder) inside your main :
/var/www/main:
/var/www/main/nested:
then your config :
location /laravel-test {
alias /var/www/main/laravel-test/public;
try_files $uri $uri/ @laravelTest;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
location @laravelTest {
rewrite /laravel-test/(.*)$ /laravel-test/index.php?/$1 last;
}
Here's a solution I came to using Nginx 1.13 and PHP-7.2 after googling for hours.
Writeup/full explanation on putting a php app in a subdirectory here .
Three important parts are:
root
vs alias
is doing location
block to do the rewrite
successfully SCRIPT_FILENAME
Here's the solution I came to (note the apps live in different locations on the disk drive):
server {
listen 80 default_server;
root /var/www/top/public;
index index.html index.htm index.php;
server_name _;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /nested {
alias /var/www/nested/public;
try_files $uri $uri/ @nested;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
location @nested {
rewrite /nested/(.*)$ /nested/index.php?/$1 last;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.