2017-04-26 214 views
0

我想實現一個反向代理,將http://www.dummy.com/foo/bar/test的請求重定向到http://127.0.0.1/hello/world。我曾嘗試通過之前添加重寫,似乎不工作...重寫url中的Nginx proxy_pass?

server { 
listen 80; 
listen [::]:80; 

server_name www.dummy.com; 

# access_log /var/log/nginx/upstream_log.log 

location/{ 
    root /usr/share/nginx/html/dummy; 
} 

location /foo/bar/test { 
    rewrite ^/foo/bar/test /hello/world break; 
    proxy_pass http://127.0.0.1/; 
    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header X-Forwarded-Proto $scheme; 

    access_log /var/log/nginx/upstream_log.log upstream_logging; 
} 

}

有什麼遺漏或配置錯誤?

+0

什麼不起作用?結果是什麼?日誌文件中是否有某些內容? –

+0

當我向郵遞員發送nginx請求時,它返回http狀態404。似乎URL沒有被重寫。我會稍後發佈日誌。謝謝 – Rex

回答

0

上述配置按預期工作......當我測試上述配置時,其他服務器配置錯誤。