0

I'm settings two projects in the same domain, a first project is a ReactJS project for my front end and a second project for my API in symfony.

I need config the virtual host of nginx so that my domain www.example.com go to my reactjs roject and www.example.com/api go to my symfony project.

The others router example www.example.com/register or www.example.com/login must be go to reactjs project and the sub folder in www.example.com/api/* go to my symfonys project.

I use Ubuntu 16.04. I've tried te next config

server {
        listen 80;
        server_name example.com www.example.com;

        location /api {
                root /var/www/symfony/public;
                try_files $uri /index.php$is_args$args;

       }

       location / {
               root /var/www/reactjs/build;
               index index.html index.htm index.nginx-debian.html;

               try_files $uri /index.html;
        }

        location ~* \.(eot|ttf|woff|woff2)$ {
                add_header Access-Control-Allow-Origin *;
        }


      error_log /var/log/nginx/Inno_FRT__error.log;
      access_log /var/log/nginx/Inno_FRT__access.log;
}

But this not work.

I have tried many different variations of the above without success.

Any assistance would be greatly appreciated.

Kelvins
  • 49
  • 2
  • 7

1 Answers1

0

If you have root /var/www/symfony/public; inside location /api, it's going to look in root /var/www/symfony/public/api. You probably want alias. Try this:

location /api/ {
    alias /var/www/symfony/public;
    try_files $uri /index.php$is_args$args;
}

For an explanation of why this is necessary, see this answer.

Also, you probably want location /api/, not location /api. Nginx does prefix matching, so location /api would match /apifoobar.

Zenexer
  • 18,788
  • 9
  • 71
  • 77