Skip to content
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

Form the file url into a complete url. #480

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

YK-Samgo
Copy link

@YK-Samgo YK-Samgo commented Jun 1, 2021

Check the file url into a complete url to support onlyoffice documentservice behind a reverse proxy with extra parts in url.

For some reasons, I deploy onlyoffice documentserver behind a reverseproxy with extra parts in path, and one item in the config file /etc/onlyoffice/documentserver/default.json is modified like this, so that the onlyoffice documentserver is served at http://192.168.0.28/utils/onlyoffice/ and everything works properly.

{
    "storage":{
        "externalHost": "/utils/onlyoffice"
    }
}

However, when it comes to config onlyoffice in nextcloud, an error occurs (I just pick out part of the log that can locate the problem):

[onlyoffice] Error: GuzzleHttp\Exception\RequestException: cURL error 3:  (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) at <<closure>>
apps/onlyoffice/lib/documentservice.php line 369 OC\Http\Client\Client->get("/utils/onlyoffi ... x", {timeout: 60})

The function OC\Http\Client\Client->get() requires a complete link as the param, but in this case, it only gets the path part of the url. A browser like chrome knows to get the resource from the same host so it works properly, but this plugin can't handle this case.

So I make it reacts like the browser and forms the file url into a complete url.

…service behind a reverse proxy with extra parts in url.
@CLAassistant
Copy link

CLAassistant commented Jun 1, 2021

CLA assistant check
All committers have signed the CLA.

@YK-Samgo
Copy link
Author

YK-Samgo commented Jun 1, 2021

By the way, I use apache2 as reverse proxy server and the conf for onlyoffice documentserver looks like this. You can use nginx if you like. Just make sure that it serves behind "/utils/onlyoffice" corresponding to the value in the config file /etc/onlyoffice/documentserver/default.json.

Define DS_VPATH /utils/onlyoffice
Define DS_ADDRESS 127.0.0.1:22500
Define DS_EXAMPLE_ADDRESS 127.0.0.1:3000
Define DS_SPELLCHECKER_ADDRESS 127.0.0.1:22501

RewriteRule ^${DS_VPATH}/example$ ${DS_VPATH}/example/ [R=301]
<Location ${DS_VPATH}/example/>
  Require all granted
  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${DS_VPATH}/example/
  ProxyAddHeaders Off
  ProxyPass "http://${DS_EXAMPLE_ADDRESS}/"
  ProxyPassReverse "http://${DS_EXAMPLE_ADDRESS}/"
  ProxyPassReverse /
</Location>

RewriteRule ^${DS_VPATH}/spellchecker$ ${DS_VPATH}/spellchecker/ [R=301]
<Location ${DS_VPATH}/spellchecker/>
  Require all granted
  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${DS_VPATH}/spellchecker/
  ProxyAddHeaders Off
  ProxyPass "http://${DS_SPELLCHECKER_ADDRESS}/"
  ProxyPassReverse "http://${DS_SPELLCHECKER_ADDRESS}/"
  ProxyPassReverse /
</Location>

RewriteRule ^${DS_VPATH}$ ${DS_VPATH}/ [R=301]
RewriteRule ^${DS_VPATH}/$ ${DS_VPATH}/welcome/ [R=301]
ProxyPassMatch ^\${DS_VPATH}(.*)(\/websocket)$ "ws://${DS_ADDRESS}/$1$2"
ProxyPass ${DS_VPATH} "http://${DS_ADDRESS}"

@LinneyS
Copy link
Member

LinneyS commented Jun 2, 2021

@YK-Samgo
Thanks for your contribution

I want to clarify:
You have added an address correction only to the conversion method
But what about saving the file after editing - there is no need to correct the address?

$newData = $documentService->Request($url);

This probably works by replacing ReplaceDocumentServerUrlToInternal. It may be enough to apply it after the GetConvertedUri ?

@YK-Samgo
Copy link
Author

YK-Samgo commented Jun 3, 2021

@LinneyS

Yes, you're right. The function ReplaceDocumentServerUrlToInternal requires modify.

Now, the files can be saved correctly.

By the way, this problem may link to some issues on failing to save documents, but I can't tell which issues.

@SergeyKorneyev
Copy link

@YK-Samgo
We have analyzed the changes you proposed and believe that they are not productive. The original issue can be avoided by specifying the external and internal addresses of the Document Server in the connector's settings.

The "externalHost" value is expected to be a host address, not a relative value. In your example, the http://192.168.0.28/utils/onlyoffice address will be used instead of the current address when creating URLs for requests to the editor.
It's better to not use this option at all, and just keep the current request address.

When using a proxy, it is necessary to correctly pass the request addresses to the editor via headers. In that case, the file URL will be correctly formed and will be accessible from Nextcloud. You can find more information and examples of proxy configuration here: https://helpcenter.onlyoffice.com/installation/docs-community-proxy.aspx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants