本文介绍了如何使用Nginx将代理反向到本地Reaction应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用nginx对我本地的Reaction应用程序执行一个简单的反向代理。我搞不懂这是怎么回事。我是否需要location /test中的根变量或别名?因为ngix找错了地址。(我正在本地运行我的React应用程序,位于本地主机:3001)

已尝试在";位置/测试&块中使用rewrite /test(.*) /$1 break

这是我的nginx.conf:

server {
    listen 81 ;
    server_name app1.localhost;

    location / {  
        root   html;
        index  index.html index.htm;
    }
    location /test {
        proxy_pass   http://localhost:3001;
    }
}
以下是我尝试进入app1.localhost:81/test时的控制台日志:

推荐答案

只需使用两个server块:

server {
    listen 81 default_server;

    location / {  
        root html;
        index index.html index.htm;
    }
}

server {
    listen 81;
    server_name app1.localhost;

    location / {  
        proxy_pass http://localhost:3001;
    }
}

这篇关于如何使用Nginx将代理反向到本地Reaction应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 06:08