2026年9月30日水曜日
2026年7月23日木曜日
NEXTJS PWA化
$ cd frontend
$ npm install @ducanh2912/next-pwa
$ npm install @ducanh2912/next-pwa
$ vi next.config.ts<<__EOF__
import withPWAInit from "@ducanh2912/next-pwa";
const withPWA = withPWAInit({
dest: "public", // サービスワーカーファイルの出力先
disable: process.env.NODE_ENV === "development", // 開発環境ではPWAを無効化
});
/** @type {import('next').NextConfig} */
const nextConfig = {
// あなたの既存のNext.js設定をここに記述
};
export default withPWA(nextConfig);
__EOF__
$ vi public/manifest.json <<__EOF__
{
"name": "Next.js PWAアプリ",
"short_name": "NextPWA",
"description": "Next.jsで作られたPWAアプリケーションです",
"start_url": "/",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#000000",
"icons": [
{
"src": "/icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/icon-512.png",
"sizes": "512x512",
"type": "image/png"
}vi
]
}
__EOF__
{
"name": "Next.js PWAアプリ",
"short_name": "NextPWA",
"description": "Next.jsで作られたPWAアプリケーションです",
"start_url": "/",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#000000",
"icons": [
{
"src": "/icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/icon-512.png",
"sizes": "512x512",
"type": "image/png"
}vi
]
}
__EOF__
$ vi src/app/layout.tsx <<__EOF__
__EOF__
2026年7月18日土曜日
海外アクセスを遮断
【更新】
# bash /root/scripts/update_geoip.sh
#!/bin/bash
# 日本のIPアドレス(IPv4 / IPv6両対応)をインポートするスクリプト
# 一時ファイルの準備
IP_FILE_V4="/tmp/jp_ips_v4.txt"
IP_FILE_V6="/tmp/jp_ips_v6.txt"
sudo firewall-cmd --permanent --delete-ipset=japan-ips-v4 2>/dev/null
sudo firewall-cmd --permanent --delete-ipset=japan-ips-v6 2>/dev/null
sudo firewall-cmd --permanent --delete-ipset=japan-ips 2>/dev/null
# 正しいURL(ftp.apnic.net)からデータを取得して抽出
curl -s http://ftp.apnic.net/stats/apnic/delegated-apnic-latest | grep 'apnic|JP|ipv4' | awk -F'|' '{printf "%s/%d\n", $4, 32-log($5)/log(2)}' > $IP_FILE_V4
curl -s http://ftp.apnic.net/stats/apnic/delegated-apnic-latest | grep 'apnic|JP|ipv6' | awk -F'|' '{printf "%s/%s\n", $4, $5}' > $IP_FILE_V6
# firewalld用の「japan-ips」セットを再作成
sudo firewall-cmd --permanent --delete-ipset=japan-ips-v4 2>/dev/null
sudo firewall-cmd --permanent --new-ipset=japan-ips-v4 --type=hash:net --family=inet
sudo firewall-cmd --permanent --ipset=japan-ips-v4 --add-entries-from-file=$IP_FILE_V4
sudo firewall-cmd --permanent --delete-ipset=japan-ips-v6 2>/dev/null
sudo firewall-cmd --permanent --new-ipset=japan-ips-v6 --type=hash:net --family=inet6
sudo firewall-cmd --permanent --ipset=japan-ips-v6 --add-entries-from-file=$IP_FILE_V6
# 設定の反映
sudo firewall-cmd --reload
# 一時ファイルの削除
#rm -f $IP_FILE_V4 $IP_FILE_V6
echo "日本のIPv4およびIPv6アドレスリストを正常に更新しました。"
__EOF__
# ① 全員に公開していた標準設定を削除
sudo firewall-cmd --permanent --zone=public --remove-service=http
sudo firewall-cmd --permanent --zone=public --remove-service=https
# ② 新しい日本リスト(IPv4/v6両方対応)だけを許可するリッチルールを追加
# 【IPv4用】日本のIPから、http、https、および各カスタムポートへのアクセスを許可
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule source ipset="japan-ips-v4" service name="http" accept'
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule source ipset="japan-ips-v4" service name="https" accept'
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule source ipset="japan-ips-v4" port port="3000" protocol="tcp" accept'
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule source ipset="japan-ips-v4" port port="8000" protocol="tcp" accept'
# 【IPv6用】日本のIPから、http、https、および各カスタムポートへのアクセスを許可
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule source ipset="japan-ips-v6" service name="http" accept'
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule source ipset="japan-ips-v6" service name="https" accept'
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule source ipset="japan-ips-v6" port port="3000" protocol="tcp" accept'
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule source ipset="japan-ips-v6" port port="8000" protocol="tcp" accept'
# ③ ファイアウォールをリロードして有効化
sudo firewall-cmd --reload
# ドコモ・ahamo・ISP系列のIPv6(2400::/12)を無条件で許可
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv6" source address="2400::/12" service name="https" accept'
# au・UQモバイル系列のIPv6(2408::/12)を無条件で許可
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv6" source address="2408::/12" service name="https" accept'
# ソフトバンク・ワイモバイル系列のIPv6(240a::/12)を無条件で許可
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv6" source address="240a::/12" service name="https" accept'
# 楽天モバイル系列のIPv6(240b::/12)を無条件で許可
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv6" source address="240b::/12" service name="https" accept'
# ファイアウォールを再読み込み
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
# 今回追加したエラーの原因となるルールを削除
sudo firewall-cmd --permanent --zone=public --remove-rich-rule='rule source ipset="japan-ips" service name="http" accept'
sudo firewall-cmd --permanent --zone=public --remove-rich-rule='rule source ipset="japan-ips" service name="https" accept'
# 反映させる
sudo firewall-cmd --reload
sudo firewall-cmd --reload
# ドコモ・ahamo・ISP系列のIPv6(2400::/12)を無条件で許可
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv6" source address="2400::/12" service name="https" accept'
# au・UQモバイル系列のIPv6(2408::/12)を無条件で許可
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv6" source address="2408::/12" service name="https" accept'
# ソフトバンク・ワイモバイル系列のIPv6(240a::/12)を無条件で許可
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv6" source address="240a::/12" service name="https" accept'
# 楽天モバイル系列のIPv6(240b::/12)を無条件で許可
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv6" source address="240b::/12" service name="https" accept'
# ファイアウォールを再読み込み
sudo firewall-cmd --reload
# LAN内(192.168.1.1〜192.168.1.254)からの通信を無条件で最優先許可
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" accept'
# 設定の反映
sudo firewall-cmd --reload
firewall-cmd --zone=public --list-all
sudo nft list chain inet firewalld filter_INPUT
元に戻す。
# 標準の公開設定を復活させるsudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
# 今回追加したエラーの原因となるルールを削除
sudo firewall-cmd --permanent --zone=public --remove-rich-rule='rule source ipset="japan-ips" service name="http" accept'
sudo firewall-cmd --permanent --zone=public --remove-rich-rule='rule source ipset="japan-ips" service name="https" accept'
sudo firewall-cmd --permanent --delete-ipset=japan-ips-v4 2>/dev/null
sudo firewall-cmd --permanent --delete-ipset=japan-ips-v6 2>/dev/null
sudo firewall-cmd --permanent --delete-ipset=japan-ips 2>/dev/null
sudo firewall-cmd --reload
【ブロックログを確認する。】
sudo firewall-cmd --set-log-denied=all
# ログ記録をオフに戻すコマンド
sudo firewall-cmd --set-log-denied=off
journalctl -xef -t firewall
sudo journalctl -f -k | grep -E "FINAL_REJECT|FINAL_DROP"
ネットワークプリンターのfirewall設定
sudo systemctl start firewalld
sudo firewall-cmd --permanent --add-service=mdns
sudo firewall-cmd --permanent --add-service=slp
【ブラザー】
sudo firewall-cmd --permanent --add-port=54925/udp
【キャノン】
sudo firewall-cmd --permanent --add-port=8611-8612/udp
sudo firewall-cmd --reload
scanimage -L
2026年7月6日月曜日
ZABBIX8.0 with postgres and nginx
■インストール前に PHP8.2以上が必要。
sudo dnf install -y epel-releasesudo dnf install -y http://rpms.remirepo.net/enterprise/remi-release-9.rpm # Rocky Linux9
sudo dnf module reset php -y
sudo dnf module enable php:remi-8.5 -y
sudo dnf update php\* -y
php -v
PHP 8.5.8 (cli) (built: Jul 1 2026 03:46:27) (NTS gcc x86_64)
Copyright (c) The PHP Group
Built by Remi's RPM repository <https://rpms.remirepo.net/> #StandWithUkraine
Zend Engine v4.5.8, Copyright (c) Zend Technologies
with Zend OPcache v8.5.8, Copyright (c), by Zend Technologies
sudo vi /etc/php-fpm.d/zabbix.conf
user = nginx
group = nginx
sudo systemctl restart php-fpm
sudo systemctl restart nginx
...
excludepkgs=zabbix*
# dnf install zabbix-server-pgsql zabbix-web-pgsql zabbix-nginx-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent
# sudo -u postgres createuser --pwprompt zabbix
# sudo -u postgres createdb -O zabbix zabbix
# zcat /usr/share/zabbix/sql-scripts/postgresql/server.sql.gz | sudo -u zabbix psql zabbix
vi /etc/zabbix/zabbix_server.conf
DBPassword=password
vi /etc/nginx/conf.d/zabbix.conf
listen 443 ssl;
server_name zabbix.dom.mydns.com;
# systemctl restart zabbix-server zabbix-agent2 nginx php-fpm
# systemctl enable zabbix-server zabbix-agent2 nginx php-fpm
# firewall-cmd --add-port=10050/tcp --zone=public --permanent
# firewall-cmd --add-port=10051/tcp --zone=public --permanent
# firewall-cmd --reload
# chown -R nginx:nginx /etc/zabbix
# chown -R nginx:nginx /usr/share/zabbix
setsebool -P httpd_can_connect_zabbix on
setsebool -P httpd_can_network_connect_db on
setsebool -P httpd_can_network_connect on
setsebool -P zabbix_can_network on
# dnf install zabbix-selinux-policy
【フロントエンドの設定】
user: Admin
password: zabbix
【NGINX】
vi /etc/nginx/conf.d/00_zabbix.conf <<__EOF__
server {
listen 443 ssl;
server_name zabbix.dom.mydns.com;
# SSL証明書のパス(お使いの環境のパスに必ず書き換えてください)
ssl_certificate /etc/pki/tls/certs/localhost.crt;
ssl_certificate_key /etc/pki/tls/private/localhost.key;
# ドキュメントルートは「/ui」の手前までに変更
root /usr/share/zabbix/ui;
index index.php;
client_max_body_size 5m;
location = /favicon.ico {
log_not_found off;
}
# /zabbix/ でアクセスされた場合の挙動
location / {
#alias /usr/share/zabbix/ui;
try_files $uri $uri/ =404;
}
location /assets {
access_log off;
expires 10d;
}
location ~ /\.ht {
deny all;
}
location ~ /(api\/|conf[^\.]|include|locale) {
deny all;
return 404;
}
location /vendor {
deny all;
return 404;
}
# PHPの実行設定
location ~ ^/(.+\.php)(/|$) {
fastcgi_pass unix:/run/php-fpm/zabbix.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param DOCUMENT_ROOT /usr/share/zabbix/ui;
fastcgi_param SCRIPT_FILENAME /usr/share/zabbix/ui/$1;
fastcgi_param PATH_TRANSLATED /usr/share/zabbix/ui/$1;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}
__EOF__
2026年7月2日木曜日
Let'sEncryptのSSL証明書
sudo dnf install epel-release -y
sudo dnf install certbot python3-certbot-nginx -y
Email Address: 期限切れ通知などを受け取るメールアドレスを入力。 Terms of Service: 利用規約への同意。 Share Email: 運営団体(EFF)へのメール共有可否。任意(
sudo dnf install certbot python3-certbot-nginx -y
certbot --nginx -d office.dom.mydns.jp -d link.dom.mydns.jp -d dom.mydns.jp
Y を入力。Y または N)。 [1]※自動的に、/etc/nginx/conf.d/00-xxxx.conf が書き換わる。 ⇐確認必要。
# tree /etc/letsencrypt
/etc/letsencrypt
├── accounts
│ └── acme-v02.api.letsencrypt.org
│ └── directory
│ └── 37fc0a779cab99282f60862f0ee7f16f
│ ├── meta.json
│ ├── private_key.json
│ └── regr.json
├── archive
│ └── office.dom.mydns.jp
│ ├── cert1.pem
│ ├── chain1.pem
│ ├── fullchain1.pem
│ └── privkey1.pem
├── cli.ini
├── live
│ ├── README
│ └── office.dom.mydns.jp
│ ├── README
│ ├── cert.pem -> ../../archive/office.dom.mydns.jp/cert1.pem
│ ├── chain.pem -> ../../archive/office.dom.mydns.jp/chain1.pem
│ ├── fullchain.pem -> ../../archive/office.dom.mydns.jp/fullchain1.pem
│ └── privkey.pem -> ../../archive/office.dom.mydns.jp/privkey1.pem
├── options-ssl-nginx.conf
├── renewal
│ └── office.dom.mydns.jp.conf
├── renewal-hooks
│ ├── deploy
│ ├── post
│ └── pre
└── ssl-dhparams.pem
sudo systemctl restart nginx
Let's Encryptの有効期限は90日
# certbot renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/office.dom.mydns.jp.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Account registered.
Simulating renewal of an existing certificate for office.dom.mydns.jp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded:
/etc/letsencrypt/live/office.dom.mydns.jp/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
【有効期限がきれた場合】
1)80ポートを開ける。NATルータ/FIREWALL
2)# certbot renew
2)# certbot renew
※443しかない場合は、TXTレコードをつくって、( 無料MYDNSではつくれない。)
# certbot certonly --manual --preferred-challenges dns -d office.dom.mydns.jp
【確認】
※デバックは、本番のDjangoとNextJSを停止して、手動でDjangoとNextJSを起動する。
sudo systemctl stop gunicorn
sudo -u nginx /usr/local/bin/pm2 status
sudo -u nginx /usr/local/bin/pm2 stop nextjs-app
デバック時の利用。
vi /et c/hosts << __EOF__
192.168.1.198 office.dom.mydns.jp link.dom.mydns.jp dom.mydns.jp
__EOF__
【Djanogo】
. ./env
pip install django-extensions Werkzeug pyOpenSSL
INSTALLED_APPS = [
...
'django_extensions',
]
cd Cert
sudo cp /etc/letsencrypt/live/office.dom.mydns.jp/fullchain.pem fullchain.pem
sudo cp /etc/letsencrypt/live/office.dom.mydns.jp/privkey.pem privkey.pem
sudo chown takahab:takahab fullchain.pem privkey.pem
python manage.py runserver_plus --cert-file Cert/ fullchain.pem --key-file Cert/privkey.pem.pem 127.0.0.1:8001
2026年6月29日月曜日
Nginx インストール&設定
# systemctl stop httpd
# systemctl disable httpd
$ pm2 start npm --name "nextjs-app" -- run start -- -p 3000
$ pm2 save
sudo -u nginx /usr/local/bin/pm2 install pm2-logrotate # 1. nginx ユーザーとして pm2-logrotate をインストール
# systemctl disable httpd
# dnf install -y nginx
# systemctl start nginx
# systemctl enable nginx
# firewall-cmd --permanent --add-service=http
# firewall-cmd --permanent --add-service=https
# firewall-cmd --reload
# vi /etc/nginx/conf.d/00_secureauth.conf << __EOF__
server {
listen 80;
server_name your_domain_or_ip; # サーバーのIPアドレスまたはドメイン名
# 1. Django (Gunicorn) へのルーティング
location /api/ {
proxy_pass http://192.168.1.198:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 2. Djangoの静的ファイル (管理画面用など)
location /static/ {
alias /home/takahab/Make/DjangoNextAuth/backend/static/;
}
# 3. Next.js へのルーティング
location / {
proxy_pass http://192.168.1.198: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;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
__EOF__
# nginx -t
# systemctl restart nginx
# setsebool -P httpd_can_network_connect 1
# systemctl restart nginx
【本番起動】
# PM2をグローバルにインストール
# npm install -g pm2
# Next.jsのプロジェクトディレクトリに移動
$ cd /home/takahab/Make/DjangoNextAuth/frontend
# PM2でNext.jsを起動(名前を "nextjs-app" とする)
$ pm2 start npm --name "nextjs-app" -- run start -- -p 3000
# サーバー起動時にPM2自体を自動起動するコマンドを生成
$ pm2 startup systemd
表示されたコマンドをコピペしてrootで実行。
# sudo env PATH=$PATH:/usr/local/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u takahab --hp /home/takahab
# su - takahab
$ pm2 save
$ pm2 start
$ cd /home/takahab/Make/DjangoNextAuth/backend
$ . ./env
$ pip install gunicorn
$ sudo vi /etc/systemd/system/gunicorn.service << __EOF__
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=nginx
Group=nginx
WorkingDirectory=/var/www/DjangoNextAuth/backend
Environment="PYTHONPATH=/var/www/DjangoNextAuth/.venv/lib/python3.14/site-packages"
ExecStart=/usr/bin/python3.14 /var/www/DjangoNextAuth/.venv/bin/gunicorn \
--workers 3 \
--bind 127.0.0.1:8000 \
Config.wsgi:application
[Install]
WantedBy=multi-user.target
__EOF__
# systemctl daemon-reload
# systemctl restart gunicorn
# systemctl status gunicorn
※Djangoでエラーの場合、
$ . ./env
手動で実行してエラーを確認。
$ ../.venv/bin/gunicorn --bind 127.0.0.1:8000 Config.wsgi:application
# semanage fcontext -a -t bin_t "/home/takahab/Make/DjangoNextAuth/\.venv/bin(/.*)?"
# semanage fcontext -a -t httpd_sys_content_t "/home/takahab/Make/DjangoNextAuth/backend(/.*)?"
restorecon -R -v /home/takahab/Make/DjangoNextAuth/
semanage fcontext -a -t bin_t "/home/takahab/Make/DjangoNextAuth/.venv/bin(/.*)?"
※Next.jsでエラーの場合。
$ pm2 delete all$ pm2 start npm --name "nextjs-app" -- run start -- -p 3000
$ pm2 save
$ pm2 delete all
[PM2][WARN] No process found
(.venv) [takahab@rocky92 frontend]$ pm2 status
┌────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
└────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
host metrics | cpu: 2.5% | ram usage: 22.7% | enp5s0: ⇓ 0.005mb/s ⇑ 0.007mb/s drop 40/min | disk: ⇓ 0.014mb/s ⇑ 0.308mb/s /m2_2 75.67% /m2_1 65.91% /boot 61.14% |
(.venv) [takahab@rocky92 frontend]$ pm2 start npm --name "nextjs-app" -- run start -- -p 3000
[PM2] Starting /usr/local/bin/npm in fork_mode (1 instance)
[PM2] Done.
┌────┬───────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├────┼───────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ nextjs-app │ default │ N/A │ fork │ 71292 │ 0s │ 0 │ online │ 0% │ 14.0mb │ takahab │ disabled │
└────┴───────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
host metrics | cpu: 0.5% | ram usage: 22.6% | enp5s0: ⇓ 0.004mb/s ⇑ 0.006mb/s drop 44/min | disk: ⇓ 0mb/s ⇑ 0.602mb/s /m2_2 75.67% /m2_1 65.91% /boot 61.14% |
(.venv) [takahab@rocky92 frontend]$ pm2 save
[PM2] Saving current process list...
[PM2] Successfully saved in /home/takahab/.pm2/dump.pm2
sudo -u nginx pm2 logs nextjs-app --lines 50
vi /var/lib/nginx/.pm2/logs/nextjs-app-out.log
vi /var/lib/nginx/.pm2/logs/nextjs-app-error.log
$ pm2 kill
$ sudo -u nginx /usr/local/bin/pm2 kill
【ログローテート】
vi /etc/systemd/journald.conf<< __EOF__
SystemMaxUse=50M
__EOF__
systemctl restart systemd-journald
sudo -u nginx /usr/local/bin/pm2 set pm2-logrotate:max_size 10M # 2. ログファイルの最大サイズを「10MB」に制限
sudo -u nginx /usr/local/bin/pm2 set pm2-logrotate:retain 10 # 3. 過去何世代(何ファイル分)残すかを設定
sudo -u nginx /usr/local/bin/pm2 set pm2-logrotate:rotateInterval '0 0 * * *' # 4. ログを毎日深夜に強制ローテートする
sudo -u nginx /usr/local/bin/pm2 set pm2-logrotate:retain 10 # 3. 過去何世代(何ファイル分)残すかを設定
sudo -u nginx /usr/local/bin/pm2 set pm2-logrotate:rotateInterval '0 0 * * *' # 4. ログを毎日深夜に強制ローテートする
【ローカルSSL】
mkdir -p /etc/nginx/ssl
cp /var/www/DjangoNextAuth/backend/Cert/localhost+2.pem /etc/nginx/ssl/server.crt
cp /var/www/DjangoNextAuth/backend/Cert/localhost+2-key.pem /etc/nginx/ssl/server.key
chmod 600 /etc/nginx/ssl/server.key
chown -R nginx:nginx /etc/nginx/ssl/
# vi /etc/nginx/conf.d/00_secureauth.conf<<__EOF__
# ==========================================
# 1. HTTP (80番ポート) の設定: HTTPS へ自動転送
# ==========================================
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://$host$request_uri; # すべて HTTPS へ強制リダイレクト
}
# ==========================================
# 2. HTTPS (443番ポート) の本番ルーティング設定
# ==========================================
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name _;
# 💡 ローカルの SSL 証明書と秘密鍵を指定
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
# SSLのセキュリティ最適化設定(モダンな暗号化)
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
# ① Django API
location /api/ {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# ② Django ポータル
location /portal/ {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# ③ Django 管理画面
location /admin/ {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# ④ Djangoの静的ファイル
location /static/ {
alias /var/www/DjangoNextAuth/backend/static/;
}
# ⑤ それ以外すべてを Next.js へ
location / {
proxy_pass http://127.0.0.1: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;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
__EOF__
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
systemctl restart nginx
2026年6月25日木曜日
ソーシャルアカウント認証の実装
【メール送信】
https://mailtrap.io/signin
セキュリティとログイン ->2段階認証プロセス-> 有効
検索まどから「アプリ パスワード」検索
検索まどから「アプリ パスワード」検索
アプリ名を入力
54 #----------------------------------------
55 # GMAIL ACCOUNT Free 500通まで
56 #----------------------------------------
57 ENV_EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
58 ENV_EMAIL_HOST='smtp.googlemail.com'
59 ENV_EMAIL_PORT='587'
60 ENV_EMAIL_USE_TLS='True'
61 ENV_EMAIL_HOST_USER='xxxxxx@gmail.com'
62 ENV_EMAIL_HOST_PASSWORD='xxxx xxxx xxxx xxxx'
63 ENV_DEFAULT_FROM_EMAIL='XXXXXXX<noreply@secureauth.com>'
64 ENV_DEFAULT_FROM_EMAIL='xxxxxx@gmail.com'
ソーシャルアカウント認証
【Google Cloud Console】https://console.cloud.google.com/welcomeOAuth 2.0 クライアント ID
・settings.py
INSTALLED_APPS = [
...
"django_extensions",
]
左上3本線から
APIサービスー>認証情報
OAuth 2.0 クライアント ID
アプリ情報
・プロジェクトの構成
・アプリ名
・ユーザサポートメール
対象
外部
連絡先
認証情報を作成
OAuthクライアントID
OAuthクライアントID
アプリケーションの種類:ウェブアプリケーション
名前:SecureAuth2026
URL1:http://localhost:3000
【GITHUB】
作成
GitHub の右上アイコン ➔ Settings ➔ 左下の Developer Settings ➔ OAuth Apps
New OAuth App
Something users will recognize and trust.
The full URL to your application homepage.
This is displayed to all users of your application.
- http://localhost:3000/auth/github-callback
Your application’s callback URL. Read our OAuth documentation for more information.
【X】
【facebook】
https://developers.facebook.com/apps/
アプリ設定ー>ベーシック-> ユースケース-> 設定
https必須( httpは受けつけないもよう)
【Django+Next.js HTTPSデバック】
■Django
pip install django-extensions Werkzeug・settings.py
INSTALLED_APPS = [
...
"django_extensions",
]
CORS_ALLOWED_ORIGINS
CSRF_TRUSTED_ORIGINS
CORS_ALLOW_CREDENTIALS
・起動
python manage.py runserver_plus --cert-file cert.crt
CSRF_TRUSTED_ORIGINS
CORS_ALLOW_CREDENTIALS
・起動
python manage.py runserver_plus --cert-file cert.crt
sudo cp cert.crt /etc/pki/ca-trust/source/anchors/
sudo update-ca-trust
■next.js
npx next dev --experimental-https
2026年6月20日土曜日
GITHUBの使い方
======================================================================
GIT CHEAT SHEET (日常開発用)
======================================================================
【 1. 毎日の基本ルーティン(保存と送信) 】
今の状態を確認する : git status
すべての変更をリストに乗せる : git add .
メッセージ付きで記録する : git commit -m "メッセージ内容"
GitHubへアップロードする : git push origin main
GitHubから最新を取り込む : git pull origin main
----------------------------------------------------------------------
【 2. ブランチの操作(新機能の開発など) 】
ブランチの一覧を見る : git branch
新しいブランチを作って移る : git switch -c feature/作業名
既存のブランチに切り替える : git switch ブランチ名
別のブランチを今の場所に合体 : git merge ブランチ名
使い終わったブランチを消す : git branch -d ブランチ名
----------------------------------------------------------------------
【 3. 履歴の確認と変更の確認 】
これまでの履歴を一覧する : git log
履歴を1行ずつコンパクトに見る : git log --oneline
まだ add していない差分を見る : git diff
----------------------------------------------------------------------
【 4. ピンチのとき(元に戻す・やり直し) 】
ファイルの変更をすべて捨てる : git restore ファイル名
直前のコミットだけを取り消す : git reset --soft HEAD~1
コミットのメッセージを直す : git commit --amend -m "新しいメッセージ"
----------------------------------------------------------------------
【 5. 最初の準備と設定の確認 】
新しくGitの管理を始める : git init
GitHubのリポジトリをコピー : git clone URL
GitHubの住所(URL)を登録する : git remote add origin URL
登録されているURLを確認する : git remote -v
登録されているURLを変更する : git remote set-url origin URL
=============================================================
GIT CHEAT SHEET (日常開発用)
======================================================================
【 1. 毎日の基本ルーティン(保存と送信) 】
今の状態を確認する : git status
すべての変更をリストに乗せる : git add .
メッセージ付きで記録する : git commit -m "メッセージ内容"
GitHubへアップロードする : git push origin main
GitHubから最新を取り込む : git pull origin main
----------------------------------------------------------------------
【 2. ブランチの操作(新機能の開発など) 】
ブランチの一覧を見る : git branch
新しいブランチを作って移る : git switch -c feature/作業名
既存のブランチに切り替える : git switch ブランチ名
別のブランチを今の場所に合体 : git merge ブランチ名
使い終わったブランチを消す : git branch -d ブランチ名
----------------------------------------------------------------------
【 3. 履歴の確認と変更の確認 】
これまでの履歴を一覧する : git log
履歴を1行ずつコンパクトに見る : git log --oneline
まだ add していない差分を見る : git diff
----------------------------------------------------------------------
【 4. ピンチのとき(元に戻す・やり直し) 】
ファイルの変更をすべて捨てる : git restore ファイル名
直前のコミットだけを取り消す : git reset --soft HEAD~1
コミットのメッセージを直す : git commit --amend -m "新しいメッセージ"
----------------------------------------------------------------------
【 5. 最初の準備と設定の確認 】
新しくGitの管理を始める : git init
GitHubのリポジトリをコピー : git clone URL
GitHubの住所(URL)を登録する : git remote add origin URL
登録されているURLを確認する : git remote -v
登録されているURLを変更する : git remote set-url origin URL
=============================================================
【TOKEN発行・保持】
GIT コンソール画面より、
Settings->Developper settings->Personal access tokens->Tokens(classic) ー>Generatre New Tokenー>Generate New toke(classic)
Note に記入
Note に記入
Expiration(有効期限設定)
Select scopes->repo
Generate token
git config --global credential.helper store
最初のPUSHで一回だけ入力
他にSSH公開鍵を設定する方法もある。
1. Webでレポジトリ作成
まず、GIT WEBで新しいレポジトリを作成してから、ローカルPCで以下のコマンドを実行。
メインブランチをつくってPUSH
1. 最新の main からブランチを作って切り替える
git switch main
git switch main git pull origin main
5. 終わったブランチを削除する
役割が終わった古いブランチは、手元のパソコンからも削除して整理します。
メインブランチをつくってPUSH
git remote add origin https://github.com/MasanobuTakahashi/Study_NextJS
git branch -M main
git push -u origin main
🖥️ 実際のコマンドの流れ
git branch -M main
git push -u origin main
🖥️ 実際のコマンドの流れ
🌿 役割に合わせて主に2種類のブランチを使い分ける。
main(メインブランチ) # いつでも本番に公開できる状態。
feature/...(機能開発ブランチ) # 新機能の追加や、バグの修正など
(例:feature/login-page や feature/fix-bug など)
まずはベースとなる main ブランチを最新にしてから、新しい作業スペースを作る。
git switch main
git pull origin main
git switch -c feature/login
(※ git switch -c を使うと、ブランチの作成と切り替えが同時にできる)
2. ファイルを編集して、こまめに記録(コミット)する
コードを書き換えたら、進み具合に合わせて記録を残す。
(※ git switch -c を使うと、ブランチの作成と切り替えが同時にできる)
2. ファイルを編集して、こまめに記録(コミット)する
コードを書き換えたら、進み具合に合わせて記録を残す。
git status
git add .
git commit -m "ログイン画面のボタンを配置"
(※作業が終わるまで、この「add ➔ commit」を何度も繰り返す)
3. GitHubに自分のブランチをアップロードする
作業がすべて終わったら、GitHubへプッシュする。
git push -u origin develop
(※この後、GitHubのウェブ画面を開いて「プルリクエスト」を作成し、チームメンバーに確認する。)
4. 【合体後】手元の環境を最新に戻す。
GitHub上でOKが出て、無事に main へ合体(マージ)された後の手順です。
手元のパソコンを一度 main に戻して、合体された最新の状態をダウンロードします。
(※作業が終わるまで、この「add ➔ commit」を何度も繰り返す)
3. GitHubに自分のブランチをアップロードする
作業がすべて終わったら、GitHubへプッシュする。
git push -u origin develop
(※この後、GitHubのウェブ画面を開いて「プルリクエスト」を作成し、チームメンバーに確認する。)
4. 【合体後】手元の環境を最新に戻す。
GitHub上でOKが出て、無事に main へ合体(マージ)された後の手順です。
手元のパソコンを一度 main に戻して、合体された最新の状態をダウンロードします。
git switch main git pull origin main
5. 終わったブランチを削除する
役割が終わった古いブランチは、手元のパソコンからも削除して整理します。
git branch -d feature/login
■その他
■その他
・新しいURLに変更する。
git remote set-url origin https://github.com/MasanobuTakahashi/study_NextJS.git
git remote -v #確認
🚀 1. 新しく始める(初期設定)
git init # 今いるフォルダをGitの管理下に置く。最初に1回だけ実行。
git clone [URL] # GitHubなどにあるリモートリポジトリをパソコンに丸ごとコピー。
💾 2. 変更を記録する(基本の形)
💾 2. 変更を記録する(基本の形)
git status # 現在の状態を確認する。
git add # 保存するリスト(ステージ)に乗せ る。
※すべてのファイルを乗せるときは git add .
git commit -m "メッセージ" # リストに乗せたファイルを、メッセージ付きでコミット。
🕒 3. 履歴を見る。
git log # これまでのコミット履歴を一覧で表示する。
git restore [ファイル名] # ファイルを最後にコミットした状態に戻す。
🌿 4. 別の作業スペースを作る(ブランチ)
git branch # 今ある作業スペース(ブランチ)の一覧を表示する。
git switch [ブランチ名] # 指定した作業スペースに切り替える。
git switch -c [新しいブランチ名] # 新しく作りながら切り替える。
git merge [ブランチ名] # 別のブランチで作った変更を、今のブランチに合体。
☁️ 5. ネット上で共有する(リモート)
git remote add origin [URL] # ローカルのGitとGitHubのリポジトリを紐付ける。
git push origin [ブランチ名] # Localの内容を、GitHubへアップロード。
git pull origin [ブランチ名] # GitHub側にある最新のデータを、Localにダウンロード&合体。
※ status ➔ add ➔ commit ➔ push
登録:
投稿 (Atom)
cloudflare クラウドフレア
https://dash.cloudflare.com/login
-
■Rocky Linux8 ORACLE RPM インストール # curl -o oracle-database-preinstall-19c-1.0-2.el8.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL8/ap...
-
$ alias sqlplus='rlwrap -pRed -if /usr/local/opt/rlwrap-extensions/sqlplus sqlplus64' $ sqlplus user/password@192.168.1.xxx:1521/sid...
-
【タイムゾーンと日本語】 $ sudo timedatectl set-timezone Asia/Tokyo $ sudo timedatectl $ sudo localectl set-locale LANG=ja_JP.utf8 $ sudo localectl 【プロキ...