通过Nginx代理OnlyOffice遇到的问题

由于生产服务器只能开放一个对外的端口使用,导致我无法给onlyoffice的服务开启对外端口访问,所以只好通过配置路径的方式跳转到onlyoffice(以下简称oo)的服务上面。

原本以为只需要跳转到oo的服务就行,但是实际配上去之后,发现根本不是这样,请求还是一堆失败的,后面在找oo的Nginx配置文件时,发现其中一个配置文件的内容如下

#welcome page
rewrite ^/$ $the_scheme://$the_host/welcome/ redirect;

#support old version
rewrite ^\/OfficeWeb(\/apps\/.*)$ $the_scheme://$the_host/7.0.0-132/web-apps$1 redirect;

#script caching protection
rewrite ^(\/web-apps\/apps\/(?!api\/).*)$ $the_scheme://$the_host/7.0.0-132$1 redirect;

#disable caching for api.js
location ~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(web-apps\/apps\/api\/documents\/api\.js)$ {
  expires -1;
  # gzip_static on;
  alias  ../$2;
}

#suppress logging the unsupported locale error in web-apps
location ~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(web-apps)(\/.*\.json)$ {
  expires 365d;
  error_log nul crit;
  # gzip_static on;
  alias ../$2$3;
}

#suppress logging the unsupported locale error in plugins
location ~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(sdkjs-plugins)(\/.*\.json)$ {
  expires 365d;
  error_log nul crit;
  # gzip_static on;
  alias ../$2$3;
}

location ~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(web-apps|sdkjs|sdkjs-plugins|fonts)(\/.*)$ {
  expires 365d;
  # gzip_static on;
  alias ../$2$3;
}

location ~* ^(\/cache\/files.*)(\/.*) {
  alias ../server/App_Data$1;
  add_header Content-Disposition "attachment; filename*=UTF-8''$arg_filename";

  set $secret_string verysecretstring;
  secure_link $arg_md5,$arg_expires;
  secure_link_md5 "$secure_link_expires$uri$secret_string";

  if ($secure_link = "") {
    return 403;
  }

  if ($secure_link = "0") {
    return 410;
  }
}

# Allow internal service only from 127.0.0.1
location ~* ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(info|internal)(\/.*)$ {
  allow 127.0.0.1;
  deny all;
  proxy_pass http://docservice/$2$3;
}

location / {
  proxy_pass http://docservice;
}

location ~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?(\/doc\/.*) {
  proxy_pass http://docservice$2;
  proxy_http_version 1.1;
}

location /7.0.0-132/ {
  proxy_pass http://docservice/;
}

location ~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(dictionaries)(\/.*)$ {
  expires 365d;
  alias ../$2$3;
}


我发现只需要配置好 $the_host ,oo的所有访问地址会自动带上我传递的路径,这样我服务器原本的Nginx就会正确打到oo的服务上,只需要把我的Nginx配置稍微做下调整就可以了,刚好又找到了oo官方给出的Nginx配置文件

onlyoffIce GitHub Nginx配置

按照他的配置文件,对我的配置稍作调整就可以使用了

map $http_x_forwarded_proto $the_scheme {
     default $http_x_forwarded_proto;
     "" $scheme;
}

map $http_x_forwarded_host $the_host {
    default $http_x_forwarded_host;
    "" $host;
}

map $http_upgrade $proxy_connection {
  default upgrade;
  "" close;
}

location /office/ {
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection $proxy_connection;
		proxy_set_header X-Forwarded-Host $the_host/office;
		proxy_set_header X-Forwarded-Proto $the_scheme;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://localhost:9898/;
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值