2026-06-14 16:49:18 +08:00
|
|
|
# =============================================================================
|
2026-07-08 21:54:57 +08:00
|
|
|
# 企微智能IT支持服务台 — Nginx 配置(公司内网服务器版)
|
2026-06-14 16:49:18 +08:00
|
|
|
# =============================================================================
|
|
|
|
|
# 适用场景:独立域名 itsupport.servyou.com.cn,公司内网 DNS 解析
|
|
|
|
|
# 与 NAS 版的区别:
|
|
|
|
|
# 1. 移除 Cloudflare 相关头(X-Forwarded-Proto https 等)
|
|
|
|
|
# 2. server_name 改为正式域名
|
|
|
|
|
# 3. 真实 IP 直接从 $remote_addr 获取(无 CF 代理层)
|
|
|
|
|
# 4. 预留 HTTPS 配置注释(如公司有统一 SSL 终端)
|
|
|
|
|
# =============================================================================
|
|
|
|
|
events {
|
|
|
|
|
worker_connections 1024;
|
|
|
|
|
}
|
|
|
|
|
http {
|
|
|
|
|
include /etc/nginx/mime.types;
|
|
|
|
|
default_type application/octet-stream;
|
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
# 日志格式
|
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
|
|
|
'$status $body_bytes_sent "$http_referer" '
|
|
|
|
|
'"$http_user_agent"';
|
|
|
|
|
access_log /var/log/nginx/access.log main;
|
|
|
|
|
error_log /var/log/nginx/error.log warn;
|
2026-07-08 21:54:57 +08:00
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
# 真实 IP 还原(2026-06-15 v0.5.1 修复)
|
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
set_real_ip_from 10.0.0.0/8; # 内网 A 类(代理/WAF 出口)
|
|
|
|
|
set_real_ip_from 172.16.0.0/12; # 内网 B 类
|
|
|
|
|
set_real_ip_from 192.168.0.0/16; # 内网 C 类
|
|
|
|
|
set_real_ip_from 10.212.0.0/16; # VPN 网段
|
|
|
|
|
real_ip_header X-Forwarded-For; # 从 X-Forwarded-For 取最后一个非信任 IP
|
|
|
|
|
real_ip_recursive on; # 递归剥离已信任代理 IP
|
2026-06-14 16:49:18 +08:00
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
# 基础配置
|
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
sendfile on;
|
|
|
|
|
tcp_nopush on;
|
|
|
|
|
tcp_nodelay on;
|
|
|
|
|
keepalive_timeout 65;
|
|
|
|
|
types_hash_max_size 2048;
|
2026-07-08 21:54:57 +08:00
|
|
|
client_max_body_size 50m;
|
2026-06-14 16:49:18 +08:00
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
# Gzip 压缩(前端静态资源)
|
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
gzip on;
|
|
|
|
|
gzip_vary on;
|
|
|
|
|
gzip_min_length 1024;
|
|
|
|
|
gzip_types text/plain text/css text/xml text/javascript
|
2026-07-08 21:54:57 +08:00
|
|
|
application/javascript application/xml+rss
|
|
|
|
|
application/json application/ld+json;
|
2026-06-14 16:49:18 +08:00
|
|
|
# =================================================================
|
|
|
|
|
# 上游服务定义(Docker 内部网络)
|
|
|
|
|
# =================================================================
|
|
|
|
|
upstream backend_api {
|
2026-07-08 21:54:57 +08:00
|
|
|
server wecom_it_backend:8000;
|
2026-06-14 16:49:18 +08:00
|
|
|
}
|
|
|
|
|
# =================================================================
|
|
|
|
|
# HTTP 服务(监听 80 端口)
|
|
|
|
|
# =================================================================
|
|
|
|
|
server {
|
|
|
|
|
listen 80;
|
|
|
|
|
server_name itsupport.servyou.com.cn;
|
2026-07-08 21:54:57 +08:00
|
|
|
location /.well-known/acme-challenge/ {
|
|
|
|
|
root /usr/share/nginx/html;
|
|
|
|
|
}
|
|
|
|
|
location / {
|
|
|
|
|
return 301 https://$host$request_uri;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
# =================================================================
|
|
|
|
|
# HTTPS — 443 端口(主服务)
|
|
|
|
|
# =================================================================
|
|
|
|
|
server {
|
|
|
|
|
listen 443 ssl;
|
|
|
|
|
http2 on;
|
|
|
|
|
server_name itsupport.servyou.com.cn;
|
|
|
|
|
ssl_certificate /etc/nginx/ssl/itsupport.servyou.com.cn.crt;
|
|
|
|
|
ssl_certificate_key /etc/nginx/ssl/itsupport.servyou.com.cn.key;
|
|
|
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
|
|
|
ssl_ciphers HIGH:!aNULL:!MD5;
|
|
|
|
|
ssl_prefer_server_ciphers on;
|
|
|
|
|
ssl_session_cache shared:SSL:10m;
|
|
|
|
|
ssl_session_timeout 1d;
|
2026-06-14 16:49:18 +08:00
|
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
|
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
2026-07-08 21:54:57 +08:00
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
|
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-eval' https://res.wx.qq.com; style-src 'self' 'unsafe-inline';";
|
|
|
|
|
add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=()" always;
|
|
|
|
|
add_header Cross-Origin-Opener-Policy "same-origin" always;
|
|
|
|
|
add_header Cross-Origin-Embedder-Policy "unsafe-none" always;
|
|
|
|
|
add_header Cross-Origin-Resource-Policy "same-origin" always;
|
|
|
|
|
server_tokens off;
|
2026-06-14 16:49:18 +08:00
|
|
|
location = /health {
|
|
|
|
|
access_log off;
|
|
|
|
|
return 200 "healthy\n";
|
|
|
|
|
add_header Content-Type text/plain;
|
|
|
|
|
}
|
|
|
|
|
location /itdesk/ {
|
|
|
|
|
alias /usr/share/nginx/html/itdesk/;
|
|
|
|
|
index index.html;
|
|
|
|
|
try_files $uri /itdesk/index.html;
|
|
|
|
|
}
|
|
|
|
|
location /itagent/ {
|
|
|
|
|
alias /usr/share/nginx/html/itagent/;
|
|
|
|
|
index index.html;
|
|
|
|
|
try_files $uri /itagent/index.html;
|
|
|
|
|
}
|
|
|
|
|
location /itadmin/ {
|
2026-07-08 21:54:57 +08:00
|
|
|
allow 10.0.0.0/8;
|
|
|
|
|
allow 172.16.0.0/12;
|
|
|
|
|
allow 192.168.0.0/16;
|
|
|
|
|
allow 10.212.0.0/16;
|
|
|
|
|
allow 10.240.0.0/16;
|
|
|
|
|
allow 117.147.35.138;
|
|
|
|
|
allow 218.75.34.87;
|
|
|
|
|
allow 43.174.152.34;
|
|
|
|
|
deny all;
|
2026-06-14 16:49:18 +08:00
|
|
|
alias /usr/share/nginx/html/itadmin/;
|
|
|
|
|
index index.html;
|
|
|
|
|
try_files $uri /itadmin/index.html;
|
|
|
|
|
}
|
|
|
|
|
location /itportal/ {
|
|
|
|
|
alias /usr/share/nginx/html/itportal/;
|
|
|
|
|
index index.html;
|
|
|
|
|
try_files $uri /itportal/index.html;
|
|
|
|
|
}
|
|
|
|
|
location /api/ {
|
2026-07-08 21:54:57 +08:00
|
|
|
location ~ ^/api/admin/ {
|
|
|
|
|
allow 10.0.0.0/8;
|
|
|
|
|
allow 172.16.0.0/12;
|
|
|
|
|
allow 192.168.0.0/16;
|
|
|
|
|
allow 10.212.0.0/16;
|
|
|
|
|
deny all;
|
|
|
|
|
proxy_pass http://backend_api;
|
|
|
|
|
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;
|
|
|
|
|
proxy_connect_timeout 60s;
|
|
|
|
|
proxy_send_timeout 300s;
|
|
|
|
|
proxy_read_timeout 300s;
|
|
|
|
|
}
|
2026-06-14 16:49:18 +08:00
|
|
|
proxy_pass http://backend_api/;
|
2026-07-08 21:54:57 +08:00
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
proxy_redirect off;
|
2026-06-14 16:49:18 +08:00
|
|
|
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;
|
2026-07-08 21:54:57 +08:00
|
|
|
proxy_set_header Connection "";
|
2026-06-14 16:49:18 +08:00
|
|
|
proxy_connect_timeout 60s;
|
|
|
|
|
proxy_send_timeout 300s;
|
|
|
|
|
proxy_read_timeout 300s;
|
|
|
|
|
}
|
|
|
|
|
location /ws/ {
|
2026-07-08 21:54:57 +08:00
|
|
|
access_log off;
|
2026-06-14 16:49:18 +08:00
|
|
|
proxy_pass http://backend_api;
|
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
|
|
|
proxy_set_header Connection "upgrade";
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
2026-07-08 21:54:57 +08:00
|
|
|
proxy_read_timeout 86400s;
|
2026-06-14 16:49:18 +08:00
|
|
|
}
|
|
|
|
|
location = / {
|
2026-07-08 21:54:57 +08:00
|
|
|
return 302 /itportal/;
|
2026-06-14 16:49:18 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|