3

I have such a project structure

<root>/public/laravel_app/index.php — Laravel index file

<root>/public/index.php — CraftCMS index file

I want to load CraftCMS app at

https://<domain>

and Laravel app at https://<domain>/laravel_app

Here is my vhost.conf

server {
    listen 443 ssl;

    index index.php index.html;

    root /var/www/public;

    ssl_certificate       /var/www/docker/certs/nginx.crt;
    ssl_certificate_key   /var/www/docker/certs/nginx.key;

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

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

I've looked through almost all related SO questions and have tried a lot of stuff, so, if it's possible, please, send suggestions related to my config.

I'm not a sysadmin and I am an Apache user (there it works in such a way without any tweaking), so I apologize, if I'm missing something obvious.

D.R.
  • 2,540
  • 3
  • 24
  • 49
  • Is url rewriting for your CraftCMS working perfectly? So that only Laravel url rewriting is broken. Or neither both are works? – Dharma Saputra Oct 30 '17 at 10:20
  • @DharmaSaputra It's not loading Laravel. I can't get that endpoint. nginx is passing everything through the `/public/index.php`. – D.R. Oct 30 '17 at 10:22
  • @DharmaSaputra or I can make working Laravel by changing the `root /var/www/public;` to `root /var/www/public/laravel_app;`, but I **can't make working both**. – D.R. Oct 30 '17 at 10:23

2 Answers2

3

You should make 2 url rewriting I think, because laravel_app has it's own index.php for rewrite.

server {
    ...

    root /var/www/public;

    ...

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

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

    ...
}

Hope this works

Dharma Saputra
  • 1,524
  • 12
  • 17
0

change

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

to

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

Adding the $uri/ tells nginx to look for a directory with the uri name.

SmoDav
  • 11
  • 3
  • Thank you, but it's not working. It's showing to me a *CraftCMS* error page, so it's loading `/public/index.php` – D.R. Oct 30 '17 at 10:21