reactjs - Express API backend receiving requests but not responding, Nginx -


i have front end reactjs being served nginx. shown here:

server {     listen 80 default_server;     server_name website.*  www.website.*;     root /home/developer/website/frontend/build;      location / {         try_files  $uri /index.html;     }      location /api {        proxy_set_header x-real-ip $remote_addr;        proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;        proxy_pass http://127.0.0.1:4000;     }  } 

additionally, have second express app receiving requests @ 127.0.0.1:4000. front end calls fetch 'api/something' , express app receives , handles not respond, client side errors 504 (gateway time-out). ideas?

you missing upstream server directive. try this

upstream api {     server 127.0.0.1:4000; }  # remove www url server {     listen 80;     server_name www.website.com;     return 301 $scheme://website.com$request_uri; }  server {     listen 0.0.0.0:80;     server_name website.com website;     error_log  /var/log/nginx/website.com-error.log error;     access_log /var/log/nginx/website.log;      # pass request node.js server correct headers     location /api/ {         proxy_pass http://api/;         proxy_ignore_headers x-accel-expires expires cache-control;         proxy_ignore_headers set-cookie;         proxy_hide_header set-cookie;         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_redirect off;         proxy_set_header x-nginx-proxy true;     } } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -