Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Url 单侧路径操纵_Url_Proxy_Haproxy_Forward - Fatal编程技术网

Url 单侧路径操纵

Url 单侧路径操纵,url,proxy,haproxy,forward,Url,Proxy,Haproxy,Forward,在谷歌云平台中,我们确实有一个haproxy,作为我们内部VPN的代理,并将URL从GCP DNS重定向到proxy.mycompany.com(我们的haproxy),在那里我们进行进一步的操作 Haproxy来自图像2.0.8-alpine Nginx基于图像1-alpine 最近我安装了nginx,它提供静态文件 Nginx是为上的自动索引而设置的,可在url静态文件.mycompany.com上访问,并配置为显示gcs存储桶的根目录。因此,如果您访问静态文件.mycompany.com,

在谷歌云平台中,我们确实有一个haproxy,作为我们内部VPN的代理,并将URL从GCP DNS重定向到proxy.mycompany.com(我们的haproxy),在那里我们进行进一步的操作

Haproxy
来自图像
2.0.8-alpine

Nginx
基于图像
1-alpine

最近我安装了nginx,它提供静态文件

Nginx是为上的
自动索引而设置的,可在url
静态文件.mycompany.com
上访问,并配置为显示gcs存储桶的根目录。因此,如果您访问静态文件.mycompany.com
,您将看到gcs bucket的内容:

  • 目录
    静态文件
  • 桶中的任何文件
静态文件
目录包含由生成的静态网站文件。 这些文件包含的路径类似于
/docu/file.md

我已成功配置haproxy,使其能够将url
website.mycompany.com
的任何请求转发到
静态文件.mycompany.com/static文件
,并通过在haproxy配置的
后端部分
中配置,显示生成的静态网站:

acl p_root path -i /
http-request set-path /static-files/\1 if p_root
每次我访问
website.mycompany.com
时,路径都会重定向到
website.mycompany.com/static files
(实际上是
static files.mycompany.com/static files

然而,该网站被破坏了:

  • css未加载,文件位于/中,请求的目标是
    website.mycompany.com/mycss.file
    ,但由于上面的路径操作,可以在
    website.mycompany.com/static files/mycss.file
    下找到该文件
  • 网站上的每个链接都死掉了,请求
    website.mycompany.com/my-link-to-file
    ,但文件仍在保存中
    website.mycompany.com/static files/my link to file
我配置haproxy的可能性有限,很可能我可以将参数添加到现有的后端和前端部分,这里我提供了我无法更改的参数:

    global
    log stdout format raw local0 info
    maxconn  30000
    tune.ssl.default-dh-param 2048
resolvers vpc
    parse-resolv-conf
    hold valid 120s
defaults
    mode    http
    log     global
    option  dontlognull
    #option  tcplog
    option  httplog
    option  forwardfor
    option  redispatch
    maxconn 3000
    retries 3
    timeout connect 5s
    timeout client  50s
    timeout server  50s
    timeout tunnel  1h
    timeout client-fin 30s
    timeout http-keep-alive 4s
    balance roundrobin
    default-server check resolvers vpc
    default-server on-marked-down shutdown-sessions
    default-server max-reuse 100

frontend http
    bind *:80
    redirect scheme https code 302 if !{ ssl_fc }
    monitor-uri /_healtz
    use_backend %[hdr(host),lower]

frontend https
    bind *:443 ssl no-sslv3 crt /config/haproxy_certificate.pem alpn http/1.1,h2
    http-response add-header Via 1.1\ %[env(HOSTNAME)]
    http-request add-header Via 1.1\ %[env(HOSTNAME)]
    http-request add-header X-Forwarded-Proto https
    http-request capture req.hdr(Host) len 40
    http-request capture req.hdr(User-Agent) len 120
    use_backend %[hdr(host),lower]

backend proxy.mycompany.com
    stats enable
    stats uri /
我希望实现以下目标:

通过访问
website.mycompany.com
我将被转发到后台的
静态文件.mycompany.com/static文件
,但是URL将保持为
website.mycompany.com
,因此生成的静态网站路径保持工作,静态网站也保持工作。还是我错了

我愿意接受任何合理的建议


谢谢

嗯,最后还是很简单的

http-request replace-uri ([^/:]*://[^/]*)?(.*) \1/static-files\2
成功了

编辑:

避免/静态文件/静态文件/

    acl remove_static-files path_beg -i /architecture-diagrams
    http-request replace-uri ([^/:]*://[^/]*)?(.*) \1/static-files\2 if !remove_static-files