Question
Nginx Config for serving Laravel from within a subdirectory of Wordpress
I’m having an nginx problem. I have a WordPress installation and I’m trying to serve a laravel app from a subdirectory.
home/foo/var/www/html
is WP
home/foo/var/www/html/app
is Laravel
home/foo/var/www/html/app/public
is what I want to serve
My current config (written after searching this forum and StackOverflow):
server {
listen 80;
listen [::]:80;
root /home/foo/var/www/html;
index index.php index.html index.htm;
server_name foo.com www.foo.com;
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
include fastcgi_params;
}
location ^~ /app {
alias home/foo/var/www/html/app/public;
try_files $uri $uri/ @app;
location ~ /app/.+\.php$ {
fastcgi_split_path_info ^(/app/.+?\.php)(/.*)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
}
}
location @app {
rewrite /app/(.*)$ /app/index.php?/$1 last;
}
location ~ /\.ht {
deny all;
}
}
can anyone tell me what i’m doing incorrectly?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×