0

I have a server and ip address, without domain. I need to place two projects on the same ip address, one is /api, another - /front.

So it should be like 123.123.123.123/api, 123.123.123.123/front

Here is what I tried to do without success (it says "welcome to nginx" when I visit /front and 404 when I visit /api):

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    index index.php index.html index.htm index.nginx-debian.html;

    location /api {
        root /var/www/api/pubic;
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ /api/.+\.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.1-fpm.sock;
    }

    location /front {
        root /var/www/front/dist;
        try_files $uri $uri/ /index.html;
    }
}

I'm pretty sure this is somewhat obvious, but I don't know much about nginx configuration, just tried an example from SO.

I use Laravel for /api, and VueJS for /front if it matters.

2
  • What should /index.html return? Currently its pointing to the Welcome page! If you meant /front/index.html you need to put that at the end of the try_files statement. Where are your files located? /var/www/front/dist/... or /var/www/front/dist/front/...? Your configuration currently assumes the latter. Commented Jul 31, 2018 at 19:19

1 Answer 1

1

Most likely your issue is the root directive in your configuration.

location /api {
    root /var/www/api/pubic;
    try_files $uri $uri/ /index.php?$query_string;
}

Here, when you try to load http://123.123.123.123/api, nginx loads /var/www/api/pubic/api/index.php. That is, nginx appends the directory in location directive to root when looking up the resource.

If you want to load /var/www/api/pubic/index.php, you need to use alias /var/www/api/pubic.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .