Skip to content

Add X-Forwarded-Prefix header #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apache/proxy-to-virtual-path.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Listen 80
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule unixd_module modules/mod_unixd.so
Expand All @@ -22,7 +23,7 @@ Define DS_ADDRESS backendserver-address
SetEnvIf Host "^(.*)$" THE_HOST=$1
RequestHeader setifempty X-Forwarded-Proto http
RequestHeader setifempty X-Forwarded-Host %{THE_HOST}e
RequestHeader edit X-Forwarded-Host (.*) $1${VPATH}
RequestHeader setifempty X-Forwarded-Prefix ${VPATH}
ProxyAddHeaders Off
</Location>

Expand Down
4 changes: 2 additions & 2 deletions haproxy/proxy-to-virtual-path.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ frontend default_port_80
default_backend default_service
backend default_service
acl existing-x-forwarded-host req.hdr(X-Forwarded-Host) -m found
http-request add-header X-Forwarded-Host %[req.hdr(Host)]/documentserver-virtual-path unless existing-x-forwarded-host
reqrep ^([^\ :]*)\ /documentserver-virtual-path/(.*) \1\ /\2
http-request add-header X-Forwarded-Prefix /documentserver-virtual-path unless existing-x-forwarded-host
http-request replace-path /documentserver-virtual-path[/]?(.*) /\1
server onlyoffice-documentserver backendserver-address:80
3 changes: 3 additions & 0 deletions iis/proxy-to-virtual-path/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ Add IIS server variables. You will need to add `HTTP_X_FORWARDED_PROTO`,`HTTP_X_
* In the right-side menu locate **Manage Server Variables** and click **View Server Variables**.
* Use the **Add...** action and add the `HTTP_X_FORWARDED_PROTO`,`HTTP_X_FORWARDED_HOST`,`HTTP_THE_SCHEME` and `HTTP_THE_HOST` one after another.
More information on adding the variables to the IIS server can be found [here](https://www.iis.net/learn/extensions/url-rewrite-module/setting-http-request-headers-and-iis-server-variables).


For example to work correctly, you need to add a virtual path to the documentserver configuration file %ProgramW6432%\ONLYOFFICE\example\config\local.json: server.siteUrl: "/documentserver-virtual-path/"
3 changes: 2 additions & 1 deletion iis/proxy-to-virtual-path/web.config
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
</conditions>
<serverVariables>
<set name="HTTP_X_FORWARDED_PROTO" value="{HTTP_THE_SCHEME}" replace="true" />
<set name="HTTP_X_FORWARDED_HOST" value="{HTTP_THE_HOST}/documentserver-virtual-path" replace="true" />
<set name="HTTP_X_FORWARDED_HOST" value="{HTTP_THE_HOST}" replace="true" />
<set name="HTTP_X_FORWARDED_PREFIX" value="/documentserver-virtual-path" />
</serverVariables>
<action type="Rewrite" url="http://docservice{R:1}" />
</rule>
Expand Down
3 changes: 2 additions & 1 deletion nginx/proxy-to-virtual-path.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ map $http_upgrade $proxy_connection {

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Forwarded-Host $the_host/documentserver-virtual-path;
proxy_set_header X-Forwarded-Host $the_host;
proxy_set_header X-Forwarded-Proto $the_scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Prefix /documentserver-virtual-path;


server {
Expand Down
2 changes: 1 addition & 1 deletion traefik/proxy-to-virtual-path.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defaultEntryPoints = ["http"]
passHostHeader = true

[frontends.docservice.headers.customrequestheaders]
X-Forwarded-Host = "{{TRAEFIK_HOST}}/documentserver-virtual-path"
X-Forwarded-Prefix = "/documentserver-virtual-path"

[frontends.docservice.routes.vpath]
rule = "PathPrefixStrip:/documentserver-virtual-path/"