Nginx Configuration Issues for Laravel Installed Inside WordPress

I have installed LEMP stack on my cloud VPS at digitalocean. I have installed WordPress on my root domain and then installed laravel in a folder inside WordPress like so.

http://www.mydomain.com (WordPress)
http://www.mydomain.com/larapp (Laravel Installation)

Read More

Previously I was on LAMP stack and everything was working fine. I then migrated to LEMP stack and the app stopped working.

I have tried for 2 days now and found no success. This is what I have achieved until now.

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/mydomain;
    index index.php index.html index.htm;

    server_name mydomain.com www.mydomain.com;

    location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    location /larapp/.+.php$ {
        rewrite ^/larapp/(.*)$ /larapp/index.php?$1 last;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ .php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

When I visit the url http://www.mydomain.com/larapp/ I get the index page. But when I visit any other url inside larapp I get WordPress 404 error as all the urls get routed through WordPress first.

How can I make the laravel app urls to function properly. Also I want to redirect all non-www requests to www. When I request the laravel url (WordPress non-www request gets redirected to www, but laravel non-www request do not get redirected).

Any help would be appreciated.

Related posts

Leave a Reply