Eu tenho um aplicativo mern em que o front-end parece estar funcionando bem, enquanto o back-end não funciona.
O back-end deve funcionar em 127.0.0.1:3000/api, mas, dada a seguinte mensagem de erro, ele sempre redireciona para 127.0.0.1:3000:
2018/07/25 15:32:43 [error] 31172#0: *4 open() "/var/www/Interface-2.0/Client/dist/50x.html" failed (2: No such file or directory), client: 130.63.1.192, server: edafos.eng.yorku.ca, request: "POST /api/auth/register HTTP/1.1", upstream: "https://127.0.0.1:3000/auth/register", host: "edafos.eng.yorku.ca", referrer: "https://edafos.eng.yorku.ca/register"
Eu tentei algumas coisas, como adicionar / api no upstream e proxy_pass. Eu também comentei a reescrita no local ^ ~ / api block. Tudo foi malsucedido e sempre recebo o mesmo erro nos logs.
Este é o meu arquivo de configuração completo:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
# the IP(s) on which your node server is running. I chose port 3000.
upstream app_edafos {
server 127.0.0.1:3000;
}
#Point http requests to https
server {
listen 0.0.0.0:80;
server_name edafos.eng.yorku.ca;
server_tokens off;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name edafos.eng.yorku.ca;
ssl_certificate /etc/letsencrypt/live/my.app.ca/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/my.app.ca/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
ssl_session_cache shared:SSL:1m;
root /var/www/Interface-2.0/Client/dist;
index index.html;
location / {
try_files $uri /index.html;
error_page 405 = $uri;
}
location ^~ /api {
rewrite /api/(.*)$ /$1 break;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Ssl on;
proxy_pass https://app_edafos;
proxy_redirect off;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
Alguém tem uma sugestão sobre como corrigir esse problema? Além disso, o URL solicitado se parece com este link