By heynavigator
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?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @heynavigator,
Your Nginx configuration file looks okay with the only exception that you might want to make
alias home/foo/var/www/html/app/public;
as
root home/foo/var/www/html/app/public;
If this still doesn’t work out, can you confirm if you have any errors or what does happen when you load the website?
Additionally, I’ll recommend you to check this DigitalOcean article which explains how to configure Laravel with Nginx - Article
Indeed it doesn’t cover your case, however what it has been explained in it, can be applied to your configuration as well.
Regards, KDSys
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.