Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ nano config.yaml

```yaml
server:
host: "0.0.0.0"
host: "::"
port: 8080
mode: "release"

Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ nano config.yaml

```yaml
server:
host: "0.0.0.0"
host: "::"
port: 8080
mode: "release"

Expand Down
2 changes: 1 addition & 1 deletion README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ nano config.yaml

```yaml
server:
host: "0.0.0.0"
host: "::"
port: 8080
mode: "release"

Expand Down
5 changes: 3 additions & 2 deletions backend/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"fmt"
"log/slog"
"net"
"net/url"
"os"
"strings"
Expand Down Expand Up @@ -688,7 +689,7 @@ type GatewaySchedulingConfig struct {
}

func (s *ServerConfig) Address() string {
return fmt.Sprintf("%s:%d", s.Host, s.Port)
return net.JoinHostPort(strings.TrimSpace(s.Host), fmt.Sprintf("%d", s.Port))
}

// DatabaseConfig 数据库连接配置
Expand Down Expand Up @@ -2299,7 +2300,7 @@ func GetServerAddress() string {

host := v.GetString("server.host")
port := v.GetInt("server.port")
return fmt.Sprintf("%s:%d", host, port)
return net.JoinHostPort(strings.TrimSpace(host), fmt.Sprintf("%d", port))
}

// ValidateAbsoluteHTTPURL 验证是否为有效的绝对 HTTP(S) URL
Expand Down
2 changes: 1 addition & 1 deletion deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ To change after installation:
2. Add or modify:
```ini
[Service]
Environment=SERVER_HOST=0.0.0.0
Environment=SERVER_HOST=::
Environment=SERVER_PORT=3000
```

Expand Down
6 changes: 3 additions & 3 deletions deploy/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# 服务器配置
# =============================================================================
server:
# Bind address (0.0.0.0 for all interfaces)
# 绑定地址(0.0.0.0 表示监听所有网络接口
host: "0.0.0.0"
# Bind address (:: for IPv6/dual-stack on most Linux systems, 0.0.0.0 for IPv4 only)
# 绑定地址(Linux 上通常 :: 可同时监听 IPv6/IPv4 双栈,0.0.0.0 为仅 IPv4
host: "::"
# Port to listen on
# 监听端口
port: 8080
Expand Down
7 changes: 5 additions & 2 deletions deploy/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SERVICE_USER="sub2api"
CONFIG_DIR="/etc/sub2api"

# Server configuration (will be set by user)
SERVER_HOST="0.0.0.0"
SERVER_HOST="::"
SERVER_PORT="8080"

# Language (default: zh = Chinese)
Expand Down Expand Up @@ -142,7 +142,7 @@ declare -A MSG_ZH=(
["server_config_title"]="服务器配置"
["server_config_desc"]="配置 Sub2API 服务监听地址"
["server_host_prompt"]="服务器监听地址"
["server_host_hint"]="0.0.0.0 表示监听所有网卡,127.0.0.1 仅本地访问"
["server_host_hint"]=":: 表示优先监听 IPv6(通常同时支持 IPv4/IPv6 双栈),0.0.0.0 为仅 IPv4,127.0.0.1 仅本地访问"
["server_port_prompt"]="服务器端口"
["server_port_hint"]="建议使用 1024-65535 之间的端口"
["server_config_summary"]="服务器配置"
Expand Down Expand Up @@ -753,6 +753,9 @@ print_completion() {
# Use PUBLIC_IP which was set by get_public_ip()
# Determine display address
local display_host="${PUBLIC_IP:-YOUR_SERVER_IP}"
if [[ "$display_host" == *:* ]]; then
display_host="[${display_host}]"
fi
if [ "$SERVER_HOST" = "127.0.0.1" ]; then
display_host="127.0.0.1"
fi
Expand Down
2 changes: 1 addition & 1 deletion deploy/sub2api.service
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ReadWritePaths=/opt/sub2api
# Environment - Server configuration
# Modify these values to change listen address and port
Environment=GIN_MODE=release
Environment=SERVER_HOST=0.0.0.0
Environment=SERVER_HOST=::
Environment=SERVER_PORT=8080

[Install]
Expand Down