如何让 axios url 指向我的 VPS nginx
How to make axios url point in my VPS nginx
我第一次在 VPS 中使用新域部署我的应用程序。
到目前为止,我的项目 axios url 是 'http://localhost:5000/posts'
我的节点服务器在 5000 端口中是 运行,我使用代理来响应以监听 5000 而不是 3000。
那么,如何将这些 url 传输到我的机器上?我必须使用我的新服务器 IP 或 example.com 域到 axios url 吗?
我能理解你想要在同一服务器上使用相同 IP 的 React 和 nginx 应用程序 运行,并且你在 3000 端口上有 React 应用程序 运行,在 5000 端口上有 nodejs。
您可以在 default.conf
中进行以下配置
server {
root /var/www/html;
server_name _;
listen 3000;
# this is the react application endpoints
location / {
try_files $uri $uri/ /index.html;
}
}
在您的 React 应用程序中,将 api 端点用作 http://127.0.0.1:5000/posts
。
所以现在,反应应用程序将由 NGINX 处理,api 由侦听 5000 的 nodejs 处理。
我第一次在 VPS 中使用新域部署我的应用程序。 到目前为止,我的项目 axios url 是 'http://localhost:5000/posts' 我的节点服务器在 5000 端口中是 运行,我使用代理来响应以监听 5000 而不是 3000。
那么,如何将这些 url 传输到我的机器上?我必须使用我的新服务器 IP 或 example.com 域到 axios url 吗?
我能理解你想要在同一服务器上使用相同 IP 的 React 和 nginx 应用程序 运行,并且你在 3000 端口上有 React 应用程序 运行,在 5000 端口上有 nodejs。
您可以在 default.conf
server {
root /var/www/html;
server_name _;
listen 3000;
# this is the react application endpoints
location / {
try_files $uri $uri/ /index.html;
}
}
在您的 React 应用程序中,将 api 端点用作 http://127.0.0.1:5000/posts
。
所以现在,反应应用程序将由 NGINX 处理,api 由侦听 5000 的 nodejs 处理。