/etc/nginx/conf.d/mysite.com.location

投稿者: | 2023年4月28日

www.mysite.com の /(ルートディレクトリ)や/xxx (サブディレクトリ)の挙動を決めるconfigです。本例は https://192.168.10.10 で動いている Turn-key linux の nextcloud をhttps://www.mysite.com/xxx でアクセスするためのリバースプロキシー設定です。

location / {
        error_log stderr; # default: logging to logd (init forwards stderr).
        #error_log /dev/null; # disable error logging after config file is read.
        # (state path of a file for access_log/error_log to the file instead.)
        index index.html;
}

location ^~ /.well-known {
        # The rules in this block are an adaptation of the rules
        # in `.htaccess` that concern `/.well-known`.

        location = /.well-known/carddav { return 301 /xxx/remote.php/dav/; }
        location = /.well-known/caldav  { return 301 /xxx/remote.php/dav/; }
        location = /.well-known/webfinger  { return 301 /xxx/index.php/.well-known/webfinger;}
        location = /.well-known/nodeinfo  { return 301 /xxx/index.php/.well-known/nodeinfo;}

        location /.well-known/acme-challenge    { try_files $uri $uri/ =404; }
        location /.well-known/pki-validation    { try_files $uri $uri/ =404; }

        # Let Nextcloud's API for `/.well-known` URIs handle all other
        # requests by passing them to the front-end controller.
        return 301 /xxx/index.php$request_uri;
    }

    location /xxx {
        rewrite ^/xxx(.*) $1 break;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Port $server_port;
        proxy_set_header X-Forwarded-Scheme $scheme;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Host $server_name;
        client_max_body_size 1G;
        proxy_pass https://192.168.10.10;

        # Websocket
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        #proxy_set_header Connection $connection_upgrade;

    }

ぶっちゃけ、よそ様の記事と nextcloud のマニュアルからコピペして作りました。文法良くわかりません。基本的に/xxx へのアクセスは proxy_pass で指定されている https://192.168.10.10 へ逆プロキシーするのですが、nextcloud は/xxx/remote.php/dav など、特殊なリダイレクトを多用するため、ヘッダーの変換をうまくこなしてやる記載が必要、、、ってことだと思います。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です