R
R
Rollex2020-06-24 17:37:31
Nginx
Rollex, 2020-06-24 17:37:31

How to set up nginx for two sites with few rules?

Task: at the address domen.ru we display a site from the directory /var/www/domen.ru
And at the address domen.ru/api we display another site on the same server located in /var/www/site.ru
everything would be fine if if it were just a directory or a direct address, and this is an argument in the query string.
The difficulty for me is that site.ru has such rules in nginx and I don’t quite understand how to correctly pass the arguments:

server_name site.ru;
location / {
        root /var/www/site.ru;
        try_files $uri /index.php$is_args$args;
        }

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


But I need site.ru/api/nd?access_token=qSIj9HdGZ to open at domain.ru/api/nd?access_token=qSIj9HdGZ and this config does not work for me:
server_name domain.ru;
location /api/ {
        root /var/www/site.ru;
        index index.php index.html;
        try_files $uri $uri/ /index.php$is_args$args;

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-06-24
@Rollex

server_name domain.ru;

    location /api/ {
        root /var/www/site.ru;
        rewrite ^ /index.php break;
    
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question