【问题标题】:How to rewrite locations in nginx reverse proxy to load owncloud page perfectly?如何在nginx反向代理中重写位置以完美加载owncloud页面?
【发布时间】:2019-09-25 05:19:01
【问题描述】:

我对使用反向代理非常缺乏经验,所以我的问题可能真的很蹩脚,抱歉。

我正在尝试通过 nginx 反向代理访问我自己的云服务器,但它无法完美加载。

我有一个使用多个位置的 NGINX 反向代理服务器。我想使用 apache 对位于另一台机器上的我自己的云服务器进行新的公共访问。 我想使用 _https://my_public_url/owncloud_ 来访问我自己的云服务器,所以我做了这样的位置块:

我在使用什么

location / {
    proxy_pass http://my_owncloudserver_url/;

一切都很好。

但在这种情况下:

location /owncloud/ {
    proxy_pass http://my_owncloudserver_url/;

我得到的 index.php/login 页面没有任何格式,因为 /apps、/core 等请求仍然来自“https://my_public_url/apps/...”、“https://my_public_url/core/” ...”等,而不是文件所在的“https://my_public_url/owncloud/core/...”,因为这些请求与 /owncloud/ 位置不匹配并且没有被代理。

我想我应该使用 rewrite 来更改这些请求的 url,将“/owncloud/”部分放入 url。

如果我使用单独的位置来匹配“/core/...”请求,例如:

location /core/ {
     rewrite  ^/core/(.*)$ /owncloud/core/$1 permanent;
}

那似乎还可以,但我不会制作很多不同的位置来匹配所有不同的请求。

我该如何解决这个问题? 我的想法已经用完了,尽管它一定很容易。

谢谢, 单身

【问题讨论】:

    标签: nginx nginx-reverse-proxy owncloud


    【解决方案1】:

    我不确定 Owncloud。但是在 Nextcloud 中你必须在 config.php https://docs.nextcloud.com/server/16/admin_manual/configuration_server/config_sample_php_parameters.html#proxy-configurations 中配置一些代理参数 请考虑使用 Nextcloud,因为它比 Owncloud 更快,如果完全开源,功能更多,并且由社区积极维护。

    【讨论】:

      【解决方案2】:

      运行容器时将OWNCLOUD_SUB_URL”更新为“/owncloud”,如果不使用容器运行则查找替代配置

      在 nginx 配置上

      location /owncloud {
          proxy_pass http://my_owncloudserver_url/owncloud;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_redirect off;
          proxy_buffering off;
      }
      

      【讨论】:

        猜你喜欢
        • 2020-12-18
        • 1970-01-01
        • 1970-01-01
        • 2019-01-20
        • 1970-01-01
        • 2015-04-14
        • 1970-01-01
        • 2014-02-01
        • 2019-03-14
        相关资源
        最近更新 更多