我正在嘗試使用 nginx 對我的本地 react 應用程式進行簡單的反向代理。我無法理解這是如何作業的。我需要一個根變數location /test還是一個別名?因為 nginx 正在查找錯誤的地址。(我在 localhost:3001 本地運行我的 react 應用程式)
已經嘗試rewrite /test(.*) /$1 break在“location /test”-block 中使用
這是我的 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:

uj5u.com熱心網友回復:
只需使用兩個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;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/339938.html
