onlyoffice-nextcloud
onlyoffice-nextcloud copied to clipboard
Form the file url into a complete url.
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.
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}"
@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? https://github.com/ONLYOFFICE/onlyoffice-nextcloud/blob/85ac3205e0bd9969b7628aefb2d76fccbd7bcdb1/controller/callbackcontroller.php#L502
This probably works by replacing ReplaceDocumentServerUrlToInternal
. It may be enough to apply it after the GetConvertedUri
?
@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.
@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.