<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nginx | YdlProg</title>
	<atom:link href="https://ydlprog.ddns.net/category/debian/nginx-debian/feed/" rel="self" type="application/rss+xml" />
	<link>https://ydlprog.ddns.net</link>
	<description>プログラマーが日々得た知識のメモ</description>
	<lastBuildDate>Sun, 16 Nov 2025 10:08:39 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>DockerでNginxリバースプロキシの起動</title>
		<link>https://ydlprog.ddns.net/2025/11/02/docker%e3%81%a7nginx%e3%83%aa%e3%83%90%e3%83%bc%e3%82%b9%e3%83%97%e3%83%ad%e3%82%ad%e3%82%b7%e3%81%ae%e8%b5%b7%e5%8b%95/</link>
					<comments>https://ydlprog.ddns.net/2025/11/02/docker%e3%81%a7nginx%e3%83%aa%e3%83%90%e3%83%bc%e3%82%b9%e3%83%97%e3%83%ad%e3%82%ad%e3%82%b7%e3%81%ae%e8%b5%b7%e5%8b%95/#respond</comments>
		
		<dc:creator><![CDATA[ydlprog]]></dc:creator>
		<pubDate>Sat, 01 Nov 2025 17:05:27 +0000</pubDate>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Nginx]]></category>
		<guid isPermaLink="false">https://ydlprog.ddns.net/?p=2471</guid>

					<description><![CDATA[目次 サーバー証明書(Let’s Encrypt)の取得certbotのインストール証明書の取得リバースプロキシ用のコンテナ作成設定ファイルの取り込み各ファイルを volumes でマウントリバースプロキシ設定 サーバー [&#8230;]]]></description>
										<content:encoded><![CDATA[

  <div id="toc" class="toc tnt-number tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-2"><label class="toc-title" for="toc-checkbox-2">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">サーバー証明書(Let’s Encrypt)の取得</a><ol><li><a href="#toc2" tabindex="0">certbotのインストール</a></li><li><a href="#toc3" tabindex="0">証明書の取得</a></li></ol></li><li><a href="#toc4" tabindex="0">リバースプロキシ用のコンテナ作成</a></li><li><a href="#toc5" tabindex="0">設定ファイルの取り込み</a></li><li><a href="#toc6" tabindex="0">各ファイルを volumes でマウント</a></li><li><a href="#toc7" tabindex="0">リバースプロキシ設定</a></li></ol>
    </div>
  </div>

<h2 class="wp-block-heading"><span id="toc1">サーバー証明書(Let’s Encrypt)の取得</span></h2>



<h3 class="wp-block-heading"><span id="toc2">certbotのインストール</span></h3>



<div class="hcb_wrap"><pre class="prism off-numbers lang-plain"><code># apt -y install certbot</code></pre></div>



<h3 class="wp-block-heading"><span id="toc3">証明書の取得</span></h3>



<div class="hcb_wrap"><pre class="prism off-numbers lang-plain"><code># certbot certonly --standalone -d ドメイン名
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address or hit Enter to skip.
 (Enter &#39;c&#39; to cancel): メールアドレス

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at:
https://letsencrypt.org/documents/LE-SA-v1.6-August-18-2025.pdf
You must agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let&#39;s Encrypt project and the non-profit organization that
develops Certbot? We&#39;d like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: n
Account registered.
Requesting a certificate for ドメイン名

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/ドメイン名/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/ドメイン名/privkey.pem
This certificate expires on 2026-02-12.
These files will be updated when the certificate renews.

NEXT STEPS:
- The certificate will need to be renewed before it expires. Certbot can automatically renew the certificate in the background, but you may need to take steps to enable that functionality. See https://certbot.org/renewal-setup for instructions.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let&#39;s Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
</code></pre></div>



<h2 class="wp-block-heading"><span id="toc4">リバースプロキシ用のコンテナ作成</span></h2>



<div class="hcb_wrap"><pre class="prism line-numbers lang-docker" data-file="compose.yaml " data-lang="Docker"><code>services:
  nginx:
    image: nginx:latest
    container_name: revproxy
    ports:
      - &quot;80:80&quot;
      - &quot;443:443&quot;
    restart: always</code></pre></div>



<p>次の工程に進むため、コンテナを起動</p>



<div class="hcb_wrap"><pre class="prism off-numbers lang-plain"><code># docker compose up -d</code></pre></div>



<h2 class="wp-block-heading"><span id="toc5">設定ファイルの取り込み</span></h2>



<div class="hcb_wrap"><pre class="prism off-numbers lang-plain"><code># mkdir -p nginx/conf.d
# docker cp revproxy:/etc/nginx/nginx.conf nginx/
# docker cp revproxy:/etc/nginx/conf.d/default.conf nginx/conf.d</code></pre></div>



<h2 class="wp-block-heading"><span id="toc6">各ファイルを volumes でマウント</span></h2>



<p>設定ファイルの取り出しが終わったら、compose.yaml を再編集します</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-docker" data-file="compose.yaml " data-lang="Docker"><code>services:
  nginx:
    image: nginx:latest
    container_name: revproxy
    ports:
      - &quot;80:80&quot;
      - &quot;443:443&quot;
    volumes:
      - ./nginx/nginx.conf:/etc/docker/nginx.conf:ro
      - ./nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf:ro
      - /etc/letsencrypt/live/ドメイン名:/etc/letsencrypt:ro
    restart: always</code></pre></div>



<h2 class="wp-block-heading"><span id="toc7">リバースプロキシ設定</span></h2>



<div class="hcb_wrap"><pre class="prism line-numbers lang-nginx" data-file="nginx/conf.d/default.conf" data-lang="nginx"><code># http
server {
    listen              80;
    listen              [::]:80;
    server_name         _;

    # httpアクセスは全てhttpsへリダイレクト
    location / {
        return 301 https://$host$request_uri;
    }
}

# https
server {
    listen              443 ssl;
    listen              [::]:443 ssl;
    ssl_certificate     /etc/nginx/server.crt;
    ssl_certificate_key /etc/nginx/server.key;
    server_name         _;

    # エラーページ
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # リバースプロキシ設定
    proxy_redirect                          off;
    proxy_set_header Host                   $host;
    proxy_set_header X-Real-IP              $remote_addr;
    proxy_set_header X-Forwarded-Host       $host;
    proxy_set_header X-Forwarded-Server     $host;
    proxy_set_header X-Forwarded-Proto      $scheme;
    proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;

    # WordPressへリバースプロキシ
    location / {
        client_max_body_size 512M;↲
        proxy_pass http://172.17.0.1:21080/;
    }

    # GitLabへリバースプロキシ
    location /gitlab {
        client_max_body_size 1000M;
        proxy_pass http://172.17.0.1:22080/gitlab;
    }
}</code></pre></div>
]]></content:encoded>
					
					<wfw:commentRss>https://ydlprog.ddns.net/2025/11/02/docker%e3%81%a7nginx%e3%83%aa%e3%83%90%e3%83%bc%e3%82%b9%e3%83%97%e3%83%ad%e3%82%ad%e3%82%b7%e3%81%ae%e8%b5%b7%e5%8b%95/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
