Skip to content

Commit f242887

Browse files
committed
feat(build): 添加快速交叉编译 Linux 目标并更新帮助信息
- 新增 linux 目标以支持快速交叉编译 Linux 可执行文件 - 移除旧的 build-linux 和 build-linux-low-cpu 目标 - 更新帮助信息以反映新的编译选项
1 parent bcd38ea commit f242887

File tree

2 files changed

+63
-10
lines changed

2 files changed

+63
-10
lines changed

Makefile

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@ run: tidy format dev
4242
build: tidy # 编译源码,依赖 tidy 目标自动添加/移除依赖包.
4343
@CGO_ENABLED=0 go build -v -ldflags "$(GO_LDFLAGS)" -o $(OUTPUT_DIR)/$(PROJECT_NAME) $(ROOT_DIR)/$(PROJECT_NAME).go
4444

45-
.PHONY: build-linux
46-
build-linux: tidy # 编译 Linux/Debian 版本(静态链接,无 CGO 依赖).
47-
@echo "构建 Linux 版本(并发数: $(GO_BUILD_PARALLEL))..."
48-
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOMAXPROCS=$(GO_BUILD_PARALLEL) go build -p $(GO_BUILD_PARALLEL) -installsuffix cgo -ldflags "$(GO_LDFLAGS)" -o $(OUTPUT_DIR)/$(PROJECT_NAME)-linux-amd64 $(ROOT_DIR)/$(PROJECT_NAME).go
4945

50-
.PHONY: build-linux-low-cpu
51-
build-linux-low-cpu: tidy # 编译 Linux/Debian 版本(低 CPU 使用,适合服务器环境).
52-
@echo "构建 Linux 版本(低 CPU 模式,并发数: 1)..."
53-
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOMAXPROCS=1 nice -n 19 go build -p 1 -installsuffix cgo -ldflags "$(GO_LDFLAGS)" -o $(OUTPUT_DIR)/$(PROJECT_NAME)-linux-amd64 $(ROOT_DIR)/$(PROJECT_NAME).go
46+
47+
.PHONY: linux
48+
linux: # 快速交叉编译 Linux 可执行文件(当前系统 -> Linux amd64).
49+
@mkdir -p $(OUTPUT_DIR)
50+
@echo "交叉编译 Linux 版本..."
51+
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$(GO_LDFLAGS)" -o $(OUTPUT_DIR)/$(PROJECT_NAME)-linux $(ROOT_DIR)/$(PROJECT_NAME).go
52+
@echo "构建完成: $(OUTPUT_DIR)/$(PROJECT_NAME)-linux"
5453

5554
.PHONY: format
5655
format: # 格式化 Go 源码.
@@ -153,8 +152,7 @@ help: # 显示帮助信息
153152
@echo "Available targets:"
154153
@echo " all - 构建项目 (默认)"
155154
@echo " build - 编译源码(当前平台)"
156-
@echo " build-linux - 编译 Linux/Debian 版本(静态链接,并发数: $(GO_BUILD_PARALLEL)"
157-
@echo " build-linux-low-cpu - 编译 Linux/Debian 版本(低 CPU 使用,适合服务器)"
155+
@echo " linux - 快速交叉编译 Linux 可执行文件(当前系统 -> Linux amd64)"
158156
@echo " run - 开发运行"
159157
@echo " dev - 开发运行"
160158
@echo " test - 运行测试"

config/nginx-default.conf

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# HTTPS 服务配置
2+
server {
3+
listen 443 ssl;
4+
server_name {server_name}; # 证书绑定的域名
5+
6+
# 移除冗余的 root/index 配置(代理模式下无效)
7+
# root html;
8+
# index index.html index.htm;
9+
10+
# 关键修改:替换为和域名匹配的证书文件路径
11+
ssl_certificate /etc/letsencrypt/live/{server_name}/fullchain.pem; # 改为你的真实证书文件
12+
ssl_certificate_key /etc/letsencrypt/live/{server_name}/privkey.pem; # 改为你的真实私钥文件
13+
14+
# SSL 基础配置
15+
ssl_session_timeout 5m;
16+
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
17+
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
18+
ssl_prefer_server_ciphers on;
19+
20+
# 新增:SSL 会话缓存(提升性能)
21+
ssl_session_cache shared:SSL:10m;
22+
23+
# gzip 配置
24+
gzip on;
25+
gzip_disable "msie6";
26+
gzip_vary on;
27+
gzip_proxied any;
28+
gzip_comp_level 6;
29+
gzip_buffers 16 8k;
30+
gzip_http_version 1.1;
31+
gzip_min_length 256;
32+
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
33+
34+
# 上传文件大小限制
35+
client_max_body_size 10m;
36+
37+
# 反向代理到后端服务
38+
location / {
39+
proxy_pass http://localhost:8088;
40+
# 推荐补充:传递真实客户端IP和请求头(避免后端获取不到正确的域名/IP)
41+
proxy_set_header Host $host;
42+
proxy_set_header X-Real-IP $remote_addr;
43+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
44+
proxy_set_header X-Forwarded-Proto $scheme;
45+
}
46+
}
47+
48+
# HTTP 重定向到 HTTPS
49+
server {
50+
listen 80;
51+
server_name {server_name};
52+
53+
# 优化:用 $host 替代硬编码域名,提升维护性
54+
return 301 https://$host$request_uri;
55+
}

0 commit comments

Comments
 (0)