Nginx proxy_pass在url中重写?

时间:2017-04-26 14:05:38

标签: nginx url-rewriting reverse-proxy

我想实现一个反向代理,将http://www.dummy.com/foo/bar/test的请求重定向到http://127.0.0.1/hello/world。我试图在传递之前添加重写,但它似乎无法正常工作......

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;
}

}

是否有遗漏或错误配置?

1 个答案:

答案 0 :(得分:0)

以上配置按预期工作...当我测试上述配置时,其他服务器配置错误。