大网数据广告活动
服务器运维问答

Nextcloud behind Ngnix reverse proxy in a subdir url

· 52CE 我爱测

I use a Ngnix reverse proxy to keep several docker services behind HTTPS and in the same DNS. Basically I want to access to Nextcloud with: https://server.<my-dns>.fr/cloud/ I have access to the initialisation page but all depend…

问题原文

原帖链接 · Opsse · CC BY-SA 4.0

I use a Ngnix reverse proxy to keep several docker services behind HTTPS and in the same DNS.

Basically I want to access to Nextcloud with: https://server.<my-dns>.fr/cloud/
I have access to the initialisation page but all dependencies don't load (css, js, images ...) because the base URL seems incorrect.

For example my browser try to load https://server.<my-dns>.fr/core/js/dist/main.js while the correct one is https://server.<my-dns>.fr/cloud/core/js/dist/main.js

My others services work as expected but not this one.

nginx.conf

events { }

http {
  proxy_cache_path /tmp/cache keys_zone=one:10m;

  # HTTP
  server {
    listen 80;
    server_name server.<my-dns>.fr;

    # For SSL cretificate validation
    location /.well-known/acme-challenge/ {
      root /var/www/certbot;
    }

    # Redirect everything to https
    location / {
      return 301 https://$host$request_uri;
    }
  }

  # HTTPS
  server {
    listen 443 ssl;
    server_name server.<my-dns>.fr;

    # HTTPS configuration
    ssl_certificate /etc/letsencrypt/live/server.<my-dns>.fr/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/server.<my-dns>.fr/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    # Auth configuration
    auth_basic "Registry realm";
    auth_basic_user_file /etc/nginx/conf.d/nginx.htpasswd;

    location /glance/ {
      proxy_pass http://localhost:61208/;
      rewrite ^/glance(.*)$ $1 break;
    }

    # Other services ...

    location /cloud/ {
      auth_basic off;
      proxy_pass http://localhost:8181/;
      rewrite ^/cloud(.*)$ $1 break;
    }
  }
}

docker-compose.yml

version: '3'

services:
  nextcloud_db:
    image: mariadb
    container_name: nextcloud_db
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: unless-stopped
    volumes:
      - ./data/db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=*****
      - MYSQL_PASSWORD=*****
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

  app:
    image: nextcloud
    ports:
      - 8181:80
    links:
      - nextcloud_db
    volumes:
      - ./data/nextcloud:/var/www/html
    restart: unless-stopped
    depends_on:
      - nextcloud_db

I understand that Nginx don't rewrite the dependencies URLs but how to solve this?
I tried to change the Nextcloud base url settings but without success. I also tried this Nextcloud in a subdir of nginx guide but I don't really understand it.

已采纳解答

原帖链接 · Opsse · CC BY-SA 4.0

With the help of Shahriar Shojib answer I solved it this way:

docker-compose.yml

...
location /cloud/ {
  auth_basic off;
  proxy_pass http://localhost:8181/cloud/;
  rewrite ^/cloud(.*)$ $1 break;
}

Nextcloud config.php

...
'overwritehost' => 'server.<my-dns>.fr',
'overwritewebroot' => '/cloud'

See the Nextcloud documentation.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-01-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。