У меня проблема с настройкой файла nginx в Ubuntu.Сценарий: у меня есть VPS, успешно установленный стек LEMP, развернутый проект Angular 2 (8) и проект Laravel (это только для API-запроса и подключения к базе данных MySQL).Я также установил узел (для универсального), и страница отлично работает, Angular делает свою работу.Проблема в том, что я не нахожу способ, чтобы мой API работал.Возможно, в моей конфигурации nginx что-то не так, как ожидалось.Вот мой файл:
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html/frontend/angular;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php;
server_name MY IP ADRESS;
charset utf-8; ## Set the charset ##
location / { ## ANGULAR(SSR-Node)
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ /index.html;
proxy_pass http://127.0.0.1:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /api {
alias /var/www/html/laravel/laravelproject/public; ## Site root for Laravel code ##
#try_files $uri $uri/ /index.php$is_args$args;
try_files $uri $uri/ /index.php?$query_string;
## Check for file existing and if there, stop ##
if (-f $request_filename) {
break;
}
## Check for file existing and if there, stop ##
if (-d $request_filename) {
break;
}
## If we get here then there is no file or directory matching request_filename ##
rewrite (.*) /api/index.php?$query_string;
## Normal php block for processing ##
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
## Don't fail or log request to favicon or robots.txt ##
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
## Access log is off and error log location is set ##
access_log off;
error_log /var/log/nginx/example.com-error.log error;
## Disable sendfile ##
sendfile off;
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
#try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
#include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
#fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
Поправьте меня, если я ошибаюсь, но запрос api (местоположение) - это ip address / api / что бы я ни дал в файле route.api?Так, как мой IP-адрес (имя сервера) / api / questions ->, когда я набираю это в браузере, я получаю ошибку 502. Я пробовал много комбинаций, но мне ничего не помогло.Любая помощь будет оценена.Если вам нужна дополнительная информация (какой-то файл в проекте Laravel), пожалуйста, спросите.Спасибо!