站点没有重定向到后端节点Nginx配置
我有一个带有节点后端的React前端,但我的NGINX设置当前不起作用。我要做的是redirect https://sales.example.com/api/stats/get_customer_count/2323232
to (节点后端服务器运行 http://127.0.0.0.1.1:3000 )但是我一直在开始404错误表明找不到API路径。不确定如何解决此问题。感谢它。谢谢
server {
root "/home/sales/frontend/dist";
index index.html index.htm;
server_name sales.example.com;
error_log /var/log/nginx/error.log;
listen 80;
location / {
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
location ~* ^/api/ {
rewrite ^/api/(.*) /$1 break;
proxy_pass http://127.0.0.1:3000;
}
}
I have a react frontend with a node backend but my nginx setup is currently not working. What I want to do is redirect https://sales.example.com/api/stats/get_customer_count/2323232
to http://127.0.0.1:3000/stats/get_customer_count/2323232
(Node backend server runs on http://127.0.0.1:3000) but I keep getting 404 errors stating that the api path is not found. Not sure how to go about fixing this. Appreciate it. Thanks
server {
root "/home/sales/frontend/dist";
index index.html index.htm;
server_name sales.example.com;
error_log /var/log/nginx/error.log;
listen 80;
location / {
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
location ~* ^/api/ {
rewrite ^/api/(.*) /$1 break;
proxy_pass http://127.0.0.1:3000;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎已经在这里回答了,并且由@Dayo 很好。
将其转换为您的示例,如下所示:(注意,主要区别是代理传递中的尾部斜杠)
但是请通读
This seems to be answered here already, and the explanation written by @Dayo is good.
Translated it to your example, it looks like this: (notice, the main difference is the tailing slash in the proxy pass)
But please, read through the linked answer, before copying this over.