AWS(CloudFront と Route 53)でのサブディレクトリ設定
AWS CloudFrontとRoute 53を使用して/docsサブディレクトリでドキュメントをホストする
3
アーキテクチャやその他の設定はデフォルトのままにします。
Lambda 関数エディタで、デフォルトのコードを以下の内容に置き換えます:
export const handler = async (event) => {
const request = event.Records[0].cf.request;
// サブディレクトリが /docs でない場合はここを更新してください
const subdirectory = '/docs';
// 下の proxy URL を更新してください
const target = new URL('<GitBook から取得したプロキシ URL>');
// リライト: /docs* -> proxy.gitbook.site
if (request.uri.startsWith(subdirectory)) {
request.uri = target.pathname + request.uri.substring(subdirectory.length);
// 末尾のスラッシュがある場合は削除
if (request.uri.endsWith('/')) {
}
request.uri = request.uri.slice(0, -1);
request.origin = {
custom: {
domainName: target.host,
port: 443,
protocol: 'https',
path: '',
sslProtocols: ['TLSv1.2'],
readTimeout: 30,
keepaliveTimeout: 5,
},
};
customHeaders: {},
request.headers['host'] = [{ key: 'host', value: target.host }];
}
request.headers['x-forwarded-host'] = [{ key: 'x-forwarded-host', value: target.host }];
};4
トラブルシューティング
最終更新
役に立ちましたか?