Answer the question
In order to leave comments, you need to log in
React app and api server on the same hosting?
Hello, during the development of react, the application was running on localhost:3000 and the api server was running on localhost:1820
and it seemed like they saw each other and everything worked, but if you upload it to the hosting and bind the domain, then react starts referring to its site address. ru/api/message without finding anything, and the server also lives nearby and is only available at the ip address from vps:1820/api/message, but if the react is forced to specify the desired ip with the port, then it refuses to go to this request with an error CORS
so far comes from solutions only to make some kind of redirect request in nginx to the api server
Answer the question
In order to leave comments, you need to log in
In the Nginx host settings, configure something like this:
location ~ ^/api {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
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:1820;
}
location / {
autoindex on;
root /var/www/dist;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question