H
H
Habr2020-01-24 18:44:24
Nginx
Habr, 2020-01-24 18:44:24

How to set up the API on the same domain as the main site?

Hello everyone, how can I refer all requests sent to ex.com/api?

server {
...

    set $base_root  /var/www/html;
    root $base_root;

    location / {
        proxy_pass 'http://127.0.0.1:3000';
    }

    location ~* \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/var/www/php-fpm/sock.sock;
        try_files $uri =404;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }

    location ~* \.(css|js|jpg|jpeg|png|gif|bmp|ico|mov|swf|pdf|zip|rar)$ {
        try_files $uri =404;
    }

    location /api {
        # это место
        alias $base_root/api/web/;
        try_files $uri $uri /api/web/index.php$is_args$args;
      

       #location ~ ^/api/assets/.+\.php(/|$) {
       #    deny all;
       #}
    
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2020-01-24
@ky0

Add to location /apidirective proxy_passwhere you want.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question