@Rollex

Как настроить nginx c переменной $args?

Имею следующий конфиг:
server {  
        listen 80;
        listen [::]:80;
        root /var/www/mysite/public; 
        index index.php index.html;
        server_name mysite.ru

        location / {
            try_files $uri /index.php$is_args$args;
        }

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

Хочу чтобы по адресу api.mysite.ru открывался адрес mysite.ru/api/
Не могу настроить конфиг должным образом ниже пример как пытаюсь сделать, но он не работает:
server {  
        listen 80;
        listen [::]:80;
        root /var/www/mysite/public; 
        index index.php index.html;
        server_name api.mysite.ru

        location / {
            try_files $uri /index.php?api/$args;
        }

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        }
}
  • Вопрос задан
  • 376 просмотров
Решения вопроса 1
@dodo512
server {  
        listen 80;
        listen [::]:80;

        server_name api.mysite.ru;

        location / {
            proxy_pass http://mysite.ru/api/;
        }
}


Или
server {  
        listen 80;
        listen [::]:80;
        root /var/www/mysite/public;
        index index.php index.html;
        server_name api.mysite.ru;

        location / {
            try_files $uri /index.php?$args;
        }

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.3-fpm.sock;
            fastcgi_param REQUEST_URI /api$request_uri;
        }
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы