4

I'm currently facing a problem where a single vhost must serve two apps. One of them is WordPress, the other one is Laravel. I've managed to get it some kind of working using a URL prefix, but I can't get the homepage to work. I'm using nginx.

Scenario:

example.com/ -> WordPress (only root)
example.com/{anything} -> Laravel
example.com/s/{anything} -> WordPress

It seems like the location directive for location = / is not working for my purpose.

Current configuration:

    location @wordpress {
        rewrite /s/(.*)$ /s/index.php?/$1 last;
    }

    # The block below should serve the WordPress homepage
    location = / {
        # How to get this to work like /s/?
    }

    # The block below should serve Laravel
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    location ^~ /s {
        alias /home/wp/wp.example.com/web; 
        try_files $uri $uri/ @wordpress;

        location ~ \.php$ {
            fastcgi_param SCRIPT_FILENAME /home/wp/wp.example.com/web/index.php;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.4-fpm-web.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    }
    
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm-app.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.