Я пытаюсь создать приложение angular с api. Каждый маршрут должен идти к приложению angular, кроме маршрута API. Маршрут API должен идти в проект laravel. Но маршрут API ( / api
) не будет работать, он просто перенаправляет на приложение angular. И когда я удаляю маршрут приложения angular ( /
), я могу получить сообщение об ошибке на / api
.
Это мой файл конфигурации:
server {
listen 80;
server_name example.nl *.example.nl;
access_log /home/example/logs/access.log;
error_log /home/example/logs/error.log;
root /home/example/public_html;
location /api {
root /home/example/public_api/public;
index index.php;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
location / {
index index.html;
try_files $uri$args $uri$args/ /index.html;
}
}
Когда я удалил последний блок я смог получить ошибку: Каждый маршрут должен идти к приложению angular, кроме маршрута API. Маршрут API должен идти в проект laravel. Но маршрут API (/ api) не будет работать, он ...
Я пытаюсь создать приложение angular с api. Каждый маршрут должен идти к приложению angular, кроме маршрута API. Маршрут API должен идти в проект laravel. Но маршрут API ( / api
) не будет работать, он просто перенаправляет на приложение angular. И когда я удаляю маршрут приложения angular ( /
), я могу получить сообщение об ошибке на / api
.
Это мой файл конфигурации:
server {
listen 80;
server_name example.nl *.example.nl;
access_log /home/example/logs/access.log;
error_log /home/example/logs/error.log;
root /home/example/public_html;
location /api {
root /home/example/public_api/public;
index index.php;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
location / {
index index.html;
try_files $uri$args $uri$args/ /index.html;
}
}
Когда я удалил последний блок я смог получить ошибку: Каждый маршрут должен идти в приложение angular, кроме маршрута API. Маршрут API должен идти в проект laravel. Но маршрут API (/ api) не будет работать, он ...
Я пытаюсь создать приложение angular с api. Каждый маршрут должен идти в приложение angular, кроме маршрута API. Маршрут API должен идти в проект laravel. Но маршрут API ( / api
) не будет работать, он просто перенаправляет на приложение angular. И когда я удаляю маршрут приложения angular ( /
), я могу получить сообщение об ошибке на / api
.
Это мой файл конфигурации:
server {
listen 80;
server_name example.nl *.example.nl;
access_log /home/example/logs/access.log;
error_log /home/example/logs/error.log;
root /home/example/public_html;
location /api {
root /home/example/public_api/public;
index index.php;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
location / {
index index.html;
try_files $uri$args $uri$args/ /index.html;
}
}
Когда я удалил последний блок я смог получить ошибку: кроме маршрута API. Маршрут API должен идти в проект laravel. Но маршрут API ( / api
) не будет работать, он просто перенаправляет на приложение angular. И когда я удаляю маршрут приложения angular ( /
), я могу получить сообщение об ошибке на / api
.
Это мой файл конфигурации:
server {
listen 80;
server_name example.nl *.example.nl;
access_log /home/example/logs/access.log;
error_log /home/example/logs/error.log;
root /home/example/public_html;
location /api {
root /home/example/public_api/public;
index index.php;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
location / {
index index.html;
try_files $uri$args $uri$args/ /index.html;
}
}
Когда я удалил последний блок я смог получить ошибку: кроме маршрута API. Маршрут API должен идти в проект laravel. Но маршрут API ( / api
) не будет работать, он просто перенаправляет на приложение angular. И когда я удаляю маршрут приложения angular ( /
), я могу получить сообщение об ошибке на / api
.
Это мой файл конфигурации:
server {
listen 80;
server_name example.nl *.example.nl;
access_log /home/example/logs/access.log;
error_log /home/example/logs/error.log;
root /home/example/public_html;
location /api {
root /home/example/public_api/public;
index index.php;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
location / {
index index.html;
try_files $uri$args $uri$args/ /index.html;
}
}
Когда я удалил последний блок я смог получить ошибку:
open () "/usr/share/nginx/html/index.php" не удалось (2: нет такого файла или каталога)
Но я говорю root / home / example / public_api / public;
.
Почему он выбирает / usr / share / nginx / html
?
/ usr / share / nginx / html
- это мой маршрут по умолчанию
.
Обновление
] Nginx теперь читает правильный каталог, но PHP не работает, это мой обновленный файл конфигурации:
server {
listen 80;
server_name example.nl *.example.nl;
access_log /home/example/logs/access.log;
error_log /home/example/logs/error.log;
root /home/example/public_html;
location /api {
alias /home/example/public_api/public;
index index.php;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
location / {
index index.html;
try_files $uri$args $uri$args/ /index.html;
}
}
В журнале ошибок я получаю:
FastCGI отправлено в stderr: «Первичный сценарий неизвестен» при чтении заголовка ответа из upstream
Это контент, который я получаю в браузере:
Файл не найден.
А это содержимое завитка ( / api
):
301 перемещен навсегда
И это содержимое curl /api/index.php
:
Файл не найден.
После долгих поисков я наконец-то нашел ответ:
server {
listen 80;
server_name example.nl *.example.nl;
access_log /home/example/logs/access.log;
error_log /home/example/logs/error.log;
root /home/example/public_html;
location ^~ /api {
alias /home/example/public_api/public;
try_files $uri $uri/ @laravel;
index index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/example/public_api/public/index.php;
}
}
location @laravel {
rewrite /api/(.*)$ /api/index.php?/$1 last;
}
location / {
index index.html;
try_files $uri$args $uri$args/ /index.html;
}
}