1 Answer
- Newest
- Most votes
- Most comments
0
It seems like the error is occurring because your Nginx configuration is not correctly proxying requests to your API server. Here's what you can try to fix the issue:
- Verify that your API server is running and accessible on localhost:4000. You can do this by running curl http://localhost:4000/api/auth on your EC2 instance's terminal.
- In your Nginx configuration, replace root /opt/devParty/routes/api; with proxy_pass http://localhost:4000; to proxy all requests under /api to your API server running on port 4000. Also, remove try_files $uri /api/auth.js =404; from the location /api block.
Your updated Nginx configuration should look like this:
server {
listen 80 default_server;
server_name _;
# react app & front-end files
location / {
root /opt/devParty/client/build;
try_files $uri /index.html;
}
# node api reverse proxy
location /api {
add_header 'Access-Control-Allow-Origin' '*';
proxy_pass http://localhost:4000;
}
}
- Save the updated configuration and restart Nginx using the command sudo service nginx restart.
- Access your API server by visiting http://<your-ec2-instance-public-ip>/api/auth in your browser.
answered a year ago
Relevant content
- asked a year ago
- Accepted Answerasked 4 months ago
- asked 5 years ago
- AWS OFFICIALUpdated 2 years ago
- How do I customize my nginx configuration to modify the "client_max_body_size" in Elastic Beanstalk?AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
Thanks for the feedback! I made these changes but the console now shows error: TypeError: a.map is not a function at Profiles.js:22:30 and front-end does not load. instead now there is a blank grey screen. Do you think it's the use of require in server.js: app.use('/api/auth', require('./routes/api/auth')) along with the file structure being /routes/api/auth even though in nginx config the location is location /api ? here is a link to the github repo for my project: https://github.com/codereyes-1/DevSocial