Nginx configuration for Symfony on a sub uri

Viewed 45

I am trying to host two applications under the same domain. One nodejs (nextjs) project and a Symfony application. I was planning to use "/be" sub url for the Symfony application. I was able to setup nginx to route to the respective applications. However I am getting 404 because I cannot replace the "/be" prefix from the request uri while trying to pass the request to the PHP-FPM. I tried replacing the REQUEST_URI fastcgi parameter but same problem persists. Here's my location configurations:

    location ~ ^/be/.*$ { # for static files
        root /home/ubuntu/be-prereg/public;
        
        # remove /be/ from request url
        rewrite ^/be/(.*)$ /$1 break;
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
                root /home/ubuntu/be-prereg/public;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        fastcgi_param REQUEST_URI '/api/test';
        
        internal;
    }

    #nodejs
    location / {
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;     
    }

0 Answers
Related