0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【AB】自分用メモ

Last updated at Posted at 2025-05-11

環境準備

(a) 必要なパッケージのインストール

sudo yum update -y
sudo yum install -y nginx curl

(b) nginxの起動と自動起動設定

sudo systemctl start nginx
sudo systemctl enable nginx

(c) nginxのステータス確認

sudo systemctl status nginx

nginx設定

(a) 設定ファイルの編集

/etc/nginx/conf.d/my_website.conf
server {
    listen 80;
    server_name my-test-site.local;

    location / {
        root /usr/share/nginx/html;
        index index.html;
    }

    location /api/data {
        default_type application/json;
        add_header Cache-Control "no-store";
        return 200 '{"message": "Hello, world!"}';
    }

    location /dummy.txt {
        root /usr/share/nginx/html;
        add_header Cache-Control "no-store";
    }

    location /main.js {
        root /usr/share/nginx/html;
        add_header Cache-Control "no-store";
    }
}

(b) 設定反映と確認

sudo nginx -t
sudo systemctl reload nginx

テスト用ファイルの作成

(a) index.html

/usr/share/nginx/html/index.html
<!DOCTYPE html>
<html>
<head>
    <title>Realistic Test Page</title>
    <style>
        body { font-family: Arial, sans-serif; }
        pre { width: 100%; max-width: 600px; white-space: pre-wrap; word-wrap: break-word; }
    </style>
</head>
<body>
    <h1>Welcome to the realistic test page</h1>
    <pre id="dummy-text">Loading...</pre>
    <p>This is a realistic test page with dummy text loading and API calls.</p>
    
    <!-- JavaScriptファイルの読み込み -->
    <script src="main.js"></script>
    
    <p id="api-response">Loading API data...</p>
</body>
</html>

(b) main.js

/usr/share/nginx/html
// main.js

// APIデータの取得
async function fetchData() {
    try {
        const response = await fetch("/api/data");
        const data = await response.json();
        console.log(data);
        document.getElementById("api-response").innerText = JSON.stringify(data);
    } catch (error) {
        console.error("API Error:", error);
    }
}

// ダミーテキストの取得
async function fetchDummyText() {
    try {
        const response = await fetch("/dummy.txt");
        const text = await response.text();
        document.getElementById("dummy-text").innerText = text.substring(0, 1000);
    } catch (error) {
        console.error("Dummy Text Error:", error);
    }
}

// 初期化
fetchData();
fetchDummyText();

(c) dummy.txt (500KB)

/usr/share/nginx/html
sudo bash -c 'base64 /dev/urandom | head -c 500000 > /usr/share/nginx/html/dummy.txt'

(d) 確認

bash
1. サーバーのステータス確認
curl -I http://my-test-site.local/

2. APIレスポンスの確認
curl http://my-test-site.local/api/data

3. ダミーテキストの先頭100バイト確認
curl -s http://my-test-site.local/dummy.txt | head -c 100
または
curl -r 0-99 http://my-test-site.local/dummy.txt

4. 全ページのソースコード確認
curl http://my-test-site.local/index.html

5. レスポンスヘッダーの確認
curl -I http://my-test-site.local/index.html

6. エラーログの確認
sudo tail -n 20 /var/log/nginx/error.log

7. ポート確認 (nginxの稼働確認)
sudo netstat -tulnp | grep 80
💡 補足
/etc/hostsに以下を追加していること:
127.0.0.1 my-test-site.local
nginx.confまたはmy_website.confにキャッシュ無効化が設定されていること:

location /dummy.txt {
    root /usr/share/nginx/html;
    add_header Cache-Control "no-store";
}

WAF設定

リクエスト制限: 2リクエスト/秒
期間: 1秒
アクション期間: 1秒

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?