From bc2f16719862d5fe91062aaeed9be6f3594eb28d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9D=A6?= Date: Wed, 14 May 2025 22:27:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(init):=20=E6=B7=BB=E5=8A=A0=E9=98=BF?= =?UTF-8?q?=E9=87=8C=E4=BA=91=E6=BA=90=E5=88=9D=E5=A7=8B=E5=8C=96=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 linux-ali.sh 脚本 - 更新 README.md,添加阿里云源初始化说明 - 重命名 nginx 配置示例,从 git.sugarscat.cn 改为 example - 更新 nginx 配置示例的 README.md --- init/README.md | 11 ++++ init/linux-ali.sh | 90 +++++++++++++++++++++++++++++++ nginx/example/README.md | 33 ++++++++++++ nginx/example/nginx.conf | 49 +++++++++++++++++ nginx/git.sugarscat.cn/README.md | 29 ---------- nginx/git.sugarscat.cn/nginx.conf | 51 ------------------ nginx/nginx.conf | 10 ++-- 7 files changed, 188 insertions(+), 85 deletions(-) create mode 100644 init/linux-ali.sh create mode 100644 nginx/example/README.md create mode 100644 nginx/example/nginx.conf delete mode 100644 nginx/git.sugarscat.cn/README.md delete mode 100644 nginx/git.sugarscat.cn/nginx.conf diff --git a/init/README.md b/init/README.md index c907ab0..9dd2bc8 100644 --- a/init/README.md +++ b/init/README.md @@ -11,3 +11,14 @@ curl -sSL https://git.sugarscat.cn/me/script/-/raw/main/init/linux.sh | bash 1. 更换软件源为 `清华大学源`; 2. 更换DNS为 `114.114.114.114`,`223.5.5.5`; 3. 设置时区 `Asia/Shanghai` 和时间同步 + +```bash +curl -sSL https://git.sugarscat.cn/me/script/-/raw/main/init/linux-ali.sh | bash +``` + +进行的操作有: + +1. 更换软件源为 `阿里云源`; +2. 更换DNS为 `114.114.114.114`,`223.5.5.5`; +3. 设置时区 `Asia/Shanghai` 和时间同步 + diff --git a/init/linux-ali.sh b/init/linux-ali.sh new file mode 100644 index 0000000..b30fb8f --- /dev/null +++ b/init/linux-ali.sh @@ -0,0 +1,90 @@ +#!/bin/bash +set -euo pipefail + +echo "=== 通用 Linux 初始化脚本(阿里云版) ===" + +# 获取系统信息 +DISTRO_ID=$(grep ^ID= /etc/os-release | cut -d= -f2 | tr -d '"') +DISTRO_NAME=$(grep ^PRETTY_NAME= /etc/os-release | cut -d= -f2 | tr -d '"') +CODENAME=$(lsb_release -cs 2>/dev/null || echo "") + +echo "检测到系统: $DISTRO_NAME" + +# 设置 DNS +set_dns() { + echo "配置 DNS 到 114.114.114.114 和 223.5.5.5..." + echo -e "nameserver 114.114.114.114\nnameserver 223.5.5.5" > /etc/resolv.conf || true +} + +# 设置时区和同步时间 +set_timezone() { + echo "设置时区为 Asia/Shanghai..." + ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime || true + if command -v timedatectl >/dev/null 2>&1; then + timedatectl set-timezone Asia/Shanghai || true + timedatectl set-ntp true || true + else + echo "timedatectl 不可用,尝试使用 ntpdate..." + (apt install -y ntpdate || yum install -y ntpdate || dnf install -y ntpdate) >/dev/null 2>&1 || true + ntpdate ntp.aliyun.com || true + fi +} + +# 设置软件源 +set_mirrors() { + echo "更换软件源为阿里云镜像..." + + case "$DISTRO_ID" in + ubuntu) + cat > /etc/apt/sources.list < /etc/apt/sources.list < /etc/nginx/sites-available/example.com +``` + +启用配置 + +```bash +ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ +``` + +修改配置 + +```bash +vim /etc/nginx/sites-available/example.com +``` + +测试配置 + +```bash +nginx -t +``` + +重启 nginx + +```bash +systemctl restart nginx +``` diff --git a/nginx/example/nginx.conf b/nginx/example/nginx.conf new file mode 100644 index 0000000..dd2b699 --- /dev/null +++ b/nginx/example/nginx.conf @@ -0,0 +1,49 @@ +server { + listen 80 ; + # listen 443 ssl http2 ; + server_name example.com; + + index index.php index.html index.htm default.php default.htm default.html; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + proxy_set_header X-Real-IP $remote_addr; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + # 重定向 +# if ($scheme = http) { +# return 301 https://$host$request_uri; +# } + + # ssl 设置 +# ssl_certificate /etc/nginx/ssl/fullchain.crt; +# ssl_certificate_key /etc/nginx/ssl/privkey.key; + + ssl_protocols TLSv1.3 TLSv1.2 TLSv1.1 TLSv1; + ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; + ssl_prefer_server_ciphers on; + ssl_session_cache shared:SSL:10m; + ssl_session_timeout 10m; + add_header Strict-Transport-Security "max-age=31536000"; + error_page 497 https://$host$request_uri; + proxy_set_header X-Forwarded-Proto https; + ssl_stapling on; + ssl_stapling_verify on; + +# location ^~ / { +# proxy_pass https://127.0.0.1:8080; +# 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 REMOTE-HOST $remote_addr; +# proxy_set_header Upgrade $http_upgrade; +# proxy_set_header Connection "upgrade"; +# proxy_set_header X-Forwarded-Proto $scheme; +# proxy_http_version 1.1; +# add_header X-Cache $upstream_cache_status; +# add_header Strict-Transport-Security "max-age=31536000"; +# add_header Cache-Control no-cache; +# } +} \ No newline at end of file diff --git a/nginx/git.sugarscat.cn/README.md b/nginx/git.sugarscat.cn/README.md deleted file mode 100644 index ac4ddf3..0000000 --- a/nginx/git.sugarscat.cn/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# git.sugarscat.cn - -## Nginx 配置 - -> 该配置需要在 `/etc/nginx/ssl/` 目录下创建 `fullchain.crt` 和 `privkey.key` 证书文件。 - -下载配置 - -```bash -curl -fsSL https://git.sugarscat.cn/me/script/-/raw/main/nginx/git.sugarscat.cn/nginx.conf > /etc/nginx/sites-available/git.sugarscat.cn -``` - -启用配置 - -```bash -ln -s /etc/nginx/sites-available/git.sugarscat.cn /etc/nginx/sites-enabled/ -``` - -测试配置 - -```bash -nginx -t -``` - -重启 nginx - -```bash -systemctl restart nginx -``` diff --git a/nginx/git.sugarscat.cn/nginx.conf b/nginx/git.sugarscat.cn/nginx.conf deleted file mode 100644 index 21bbcf3..0000000 --- a/nginx/git.sugarscat.cn/nginx.conf +++ /dev/null @@ -1,51 +0,0 @@ -server { - listen 80 ; - listen 443 ssl http2 ; - server_name git.sugarscat.cn; - index index.php index.html index.htm default.php default.htm default.html; - proxy_set_header Host $host; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Host $server_name; - proxy_set_header X-Real-IP $remote_addr; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - # acme.sh - location ^~ /.well-known/acme-challenge { - allow all; - root /var/www/html; - } - # 重定向 - if ($scheme = http) { - return 301 https://$host$request_uri; - } - # ssl 设置 - ssl_certificate /etc/nginx/ssl/fullchain.crt; - ssl_certificate_key /etc/nginx/ssl/privkey.key; - - ssl_protocols TLSv1.3 TLSv1.2 TLSv1.1 TLSv1; - ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; - ssl_prefer_server_ciphers on; - ssl_session_cache shared:SSL:10m; - ssl_session_timeout 10m; - add_header Strict-Transport-Security "max-age=31536000"; - error_page 497 https://$host$request_uri; - proxy_set_header X-Forwarded-Proto https; - ssl_stapling on; - ssl_stapling_verify on; - - location ^~ / { - proxy_pass https://127.0.0.1:8080; - 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 REMOTE-HOST $remote_addr; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_http_version 1.1; - add_header X-Cache $upstream_cache_status; - add_header Strict-Transport-Security "max-age=31536000"; - add_header Cache-Control no-cache; - } -} \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 3566495..ed28246 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -50,14 +50,14 @@ http { ## gzip on; - gzip_min_length 1k; - gzip_buffers 4 16k; + gzip_min_length 1k; + gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; - gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; + gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; gzip_vary on; - gzip_proxied expired no-cache no-store private auth; - gzip_disable "MSIE [1-6]\."; + gzip_proxied expired no-cache no-store private auth; + gzip_disable "MSIE [1-6]\."; ## # Virtual Host Configs