我已经在免费EC2轮胎上部署了我的第一个React,Node,MongoDB,Nginx应用程序。后端API单独工作,前端也运行良好。但是前端API调用无法相互到达。
前端:http://18.130.30.219/ 节点API:http://18.130.30.219:5000/api/article/thumbist
default.conf如下
server {
#listen 80;
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
access_log /home/ubuntu/client/server_logs/host.access.log main;
location / {
root /home/ubuntu/client/deploy;
index index.html index.htm;
try_files $uri /index.html;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
server_tokens off;
location ~ /\.ht {
deny all;
}
}
答案 0 :(得分:1)
我遇到了一个解决方案。
location /api {
proxy_pass http://127.0.0.1:5000;
}
行必须添加到default.conf文件中。
如果您的API使用不同的端口和/或路由(例如:'/ api'),则必须如上所述进行配置。我只是MERN堆栈的初学者。
答案 1 :(得分:0)
请在前端代码中检查您的config API网址
Request URL: http://18.130.30.219/api/article/create
,它正在调用前端网址。