Docker でマッピングされたポートの転送および他のサーバーへの転送のプロセスを簡単に記録します。
Nginx のインストール#
1. debain システムのインストール#
sudo apt-get update
sudo apt-get install nginx
2. NGINX のインストールが成功したかどうかを確認します。ターミナルに以下のコマンドを入力します:#
sudo service nginx start
SSL 証明書の申請#
1. CerBot クライアントの取得#
install certbot
2. 証明書の取得#
certbot certonly --webroot -w /var/www/example -d example.com -d www.example.com
このコマンドは、example.com と www.example.com の 2 つのドメインに対して証明書を生成します。--webroot モードを使用すると、/var/www/example に.well-known フォルダが作成され、このフォルダにはいくつかの検証ファイルが含まれています。certbot は、example.com/.well-known/acme-challenge にアクセスしてドメインがこのサーバーにバインドされているかどうかを検証します。このコマンドはほとんどの場合に要件を満たしますが、一部のサービスではルートディレクトリがない場合があります(たとえば、いくつかのマイクロサービス)。その場合、certbot にはもう 1 つのモードである --standalone があります。このモードでは、ウェブサイトのルートディレクトリを指定する必要はありません。代わりに、サーバーの 443 ポートを自動的に有効にしてドメインの所有権を検証します。他のサービス(たとえば nginx)が 443 ポートを使用している場合は、このサービスを停止してから証明書が生成された後に再度有効にする必要があります。
certbot certonly --standalone -d example.com -d www.example.com
証明書が生成されると、/etc/letsencrypt/live/ ディレクトリに対応するドメインのフォルダが表示され、その中には証明書へのショートカットが格納されています。
これで最初の証明書の生成が完了しました。次は、ウェブサーバーの設定を行い、HTTPS を有効にします。
転送設定の作成#
1. NGINX リバースプロキシの設定。ターミナルに以下のコマンドを入力します:#
blog.xxxx.xxx
を設定ファイルの名前として使用します
touch /etc/nginx/sites-available/blog.xxxx.xxx
2. 設定ファイルの参考#
これは localhost の 3000 ポートに転送することを意味します
server {
listen 80;
listen [::]:80;
server_name wqq.xxxx.xxx;
return 301 https://$server_name$request_uri;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;
port_in_redirect off;
proxy_redirect http://localhost:3000 https://wqq.xxxx.xxx;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name wqq.xxxx.xxx;
ssl_certificate /etc/letsencrypt/live/wqq.xxxx.xxx/fullchain.pem; # あなたの証明書のパスに置き換えてください
ssl_certificate_key /etc/letsencrypt/live/wqq.xxxx.xxx/privkey.pem; # あなたの証明書の秘密鍵のパスに置き換えてください
# 強制的にHTTPSにリダイレクト
if ($scheme != "https") {
return 301 https://$server_name$request_uri;
}
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;
port_in_redirect off;
proxy_redirect http://localhost:3000 https://wqq.xxxx.xxx;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
}
}
3. sites-enabled のシンボリックリンクを作成します#
その後、/etc/nginx/sites-enabled で上記の /etc/nginx/sites-available/blog.xxxx.xxx ファイルにシンボリックリンクを作成する必要があります。以下のコマンドを使用します:
ln -s /etc/nginx/sites-available/blog.ryujinx.top /etc/nginx/sites-enabled/
次に、nginx の設定ファイルが正しいかどうかを確認します:sudo nginx -t
。 "Syntax OK" と表示された場合、設定が正しいことを意味し、sudo systemctl reload nginx
を実行して nginx を再起動します。これで設定が完了しました。