簡體   English   中英

我如何使用 NGINX 反向代理到本地 React 應用程序

[英]How do i use NGINX to reverse proxy to local react app

我正在嘗試使用 nginx 對我的本地 react 應用程序進行簡單的反向代理。 我無法理解這是如何工作的。 我需要location /test的根變量還是別名? 因為 nginx 正在查找錯誤的地址。 (我在 localhost:3001 本地運行我的 React 應用程序)

已經嘗試在 "location /test" rewrite /test(.*) /$1 break使用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;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM