Files
qnc-webview-v3/server/nginx-www.quannengcha.com.conf
2026-02-28 14:33:47 +08:00

420 lines
14 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Nginx 配置 - www.quannengcha.com全能查
# 含爬虫检测 + SEO 静态页回退,与 useSEO.js / generate-seo-templates.cjs 路由一致
# 部署时将 public/seo-templates/ 下所有 .html 拷贝到 /www/sites/www.quannengcha.com/static-pages/
server {
listen 80;
listen 443 ssl http2;
server_name www.quannengcha.com quannengcha.com p.quannengcha.com;
# 网站根目录SPA
root /www/sites/www.quannengcha.com/index;
# SEO 静态页面目录(与 generate-seo-templates.cjs 输出一致)
set $static_root /www/sites/www.quannengcha.com/index/static-pages;
# 默认首页
index index.php index.html index.htm default.php default.htm default.html;
# ========================================
# 爬虫检测(核心 SEO 逻辑)
# ========================================
set $is_bot 0;
# Google 爬虫
if ($http_user_agent ~* (googlebot|googlebot-image|googlebot-news|googlebot-video|mediapartners-google|adsbot-google)) {
set $is_bot 1;
}
# 百度爬虫
if ($http_user_agent ~* (baiduspider|baiduspider-mobile|baiduspider-image|baiduspider-video|baiduspider-news)) {
set $is_bot 1;
}
# 必应爬虫
if ($http_user_agent ~* (bingbot|msnbot|bingpreview)) {
set $is_bot 1;
}
# 360 爬虫
if ($http_user_agent ~* "360spider|360Spider") {
set $is_bot 1;
}
# 搜狗爬虫
if ($http_user_agent ~* "(sogou spider|sogou-orion|Sogou web spider)") {
set $is_bot 1;
}
# 头条爬虫
if ($http_user_agent ~* "bytespider|Bytespider") {
set $is_bot 1;
}
# 神马爬虫
if ($http_user_agent ~* "yisouspider|YisouSpider") {
set $is_bot 1;
}
# 其他常见爬虫
if ($http_user_agent ~* "(spider|crawl|bot|slurp|yandex|duckduckbot|facebookexternalhit|twitterbot|linkedinbot|pinterest|applebot)") {
set $is_bot 1;
}
# ========================================
# 通用代理头设置
# ========================================
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 $http_connection;
# ========================================
# 日志配置
# ========================================
access_log /www/sites/www.quannengcha.com/log/access.log main;
error_log /www/sites/www.quannengcha.com/log/error.log;
# ========================================
# Let's Encrypt 验证
# ========================================
location ^~ /.well-known/acme-challenge {
allow all;
root /usr/share/nginx/html;
}
# ========================================
# SSL 证书配置
# ========================================
ssl_certificate /www/sites/www.quannengcha.com/ssl/fullchain.pem;
ssl_certificate_key /www/sites/www.quannengcha.com/ssl/privkey.pem;
ssl_protocols TLSv1.3 TLSv1.2 TLSv1.1 TLSv1;
ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK:!KRB5:!SRP:!CAMELLIA:!SEED;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
error_page 497 https://$host$request_uri;
proxy_set_header X-Forwarded-Proto https;
add_header Strict-Transport-Security "max-age=31536000";
# ========================================
# SEO 静态文件sitemap.xml, robots.txt
# ========================================
location = /sitemap.xml {
root /www/sites/www.quannengcha.com/static-pages;
default_type application/xml;
}
location = /robots.txt {
root /www/sites/www.quannengcha.com/static-pages;
default_type text/plain;
}
# ========================================
# 首页(爬虫 → 静态页,用户 → SPA
# ========================================
location = / {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /index.html break;
}
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate";
add_header Pragma "no-cache";
add_header Expires 0;
}
# ========================================
# SEO 关键页面(与 useSEO.js / middleware 一致;子路径在前)
# ========================================
# 合作政策指南(子路径须在 /agent 之前)
location = /agent/system-guide {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /agent-system-guide.html break;
}
try_files $uri $uri/ /index.html;
}
# 个人综合风险分析
location = /inquire/riskassessment {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /inquire-riskassessment.html break;
}
try_files $uri $uri/ /index.html;
}
# 企业工商信用画像
location = /inquire/companyinfo {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /inquire-companyinfo.html break;
}
try_files $uri $uri/ /index.html;
}
# 综合履约评分检测
location = /inquire/preloanbackgroundcheck {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /inquire-preloanbackgroundcheck.html break;
}
try_files $uri $uri/ /index.html;
}
# 婚前综合背景了解
location = /inquire/marriage {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /inquire-marriage.html break;
}
try_files $uri $uri/ /index.html;
}
# 职场背景核验报告
location = /inquire/backgroundcheck {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /inquire-backgroundcheck.html break;
}
try_files $uri $uri/ /index.html;
}
# 家政人员背景核实
location = /inquire/homeservice {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /inquire-homeservice.html break;
}
try_files $uri $uri/ /index.html;
}
# 个人履约能力评估
location = /inquire/consumerFinanceReport {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /inquire-consumerFinanceReport.html break;
}
try_files $uri $uri/ /index.html;
}
# 代理中心
location = /agent {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /agent.html break;
}
try_files $uri $uri/ /index.html;
}
# 使用指南(子路径须在 /help 之前)
location = /help/guide {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /help-guide.html break;
}
try_files $uri $uri/ /index.html;
}
# 帮助中心
location = /help {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /help.html break;
}
try_files $uri $uri/ /index.html;
}
# 示例报告
location = /example {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /example.html break;
}
try_files $uri $uri/ /index.html;
}
# 客服中心
location = /service {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /service.html break;
}
try_files $uri $uri/ /index.html;
}
# 合伙人计划
location = /promote {
if ($is_bot = 1) {
root /www/sites/www.quannengcha.com/static-pages;
rewrite ^ /promote.html break;
}
try_files $uri $uri/ /index.html;
}
# ========================================
# API 代理配置
# ========================================
# 处理后端API请求
location /api {
proxy_pass http://127.0.0.1:17990;
proxy_set_header Host 127.0.0.1:$server_port;
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;
add_header X-Cache $upstream_cache_status;
proxy_set_header X-Host $host:$server_port;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 30s;
proxy_read_timeout 86400s;
proxy_send_timeout 30s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /s/ {
proxy_pass http://127.0.0.1:21204;
proxy_set_header Host 127.0.0.1:$server_port;
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;
add_header X-Cache $upstream_cache_status;
proxy_set_header X-Host $host:$server_port;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 30s;
proxy_read_timeout 86400s;
proxy_send_timeout 30s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /api/v1 {
set $target_backend "http://127.0.0.1:21204";
if ($host ~* ^([a-zA-Z0-9-]+\.)?tianyuancha\.cn$) {
set $target_backend "http://127.0.0.1:20004";
}
if ($host ~* ^([a-zA-Z0-9-]+\.)?quannengcha\.com$) {
set $target_backend "http://127.0.0.1:21204";
}
proxy_pass $target_backend;
proxy_set_header Host 127.0.0.1:$server_port;
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;
add_header X-Cache $upstream_cache_status;
proxy_set_header X-Host $host:$server_port;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 30s;
proxy_read_timeout 86400s;
proxy_send_timeout 30s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# V2
location /apiv2 {
proxy_pass http://127.0.0.1:18990;
proxy_set_header Host 127.0.0.1:$server_port;
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;
add_header X-Cache $upstream_cache_status;
proxy_set_header X-Host $host:$server_port;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 30s;
proxy_read_timeout 86400s;
}
location ^~ /api/v1/chat {
resolver 8.8.8.8 114.114.114.114 valid=10s;
resolver_timeout 5s;
set $backend "chat.guimiaokeji.com";
rewrite ^/api/v1/(.*)$ /$1 break;
proxy_pass https://$backend;
proxy_set_header Host $backend;
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 Cache-Control no-cache;
proxy_ssl_server_name off;
proxy_buffering off;
}
# ========================================
# 静态资源缓存(图片、字体等)
# ========================================
location ~* \.(png|jpg|jpeg|gif|ico|svg|webp|woff|woff2|ttf|eot|otf)$ {
expires 1y;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
# ========================================
# HTML/JS/CSS 无缓存策略
# ========================================
location ~* \.(html|htm|js|css|json|xml)$ {
add_header Cache-Control "no-store, no-cache, must-revalidate, max-age=0";
add_header Pragma "no-cache";
add_header Expires "0";
}
# ========================================
# SPA 路由回退(其他所有路由)
# ========================================
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate";
add_header Pragma "no-cache";
add_header Expires 0;
}
# ========================================
# 错误页面
# ========================================
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
# ========================================
# Gzip 压缩
# ========================================
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/javascript application/json image/svg+xml;
# ========================================
# 安全头
# ========================================
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
# ========================================
# HTTP 强制跳转 HTTPS
# ========================================
if ($scheme = http) {
return 301 https://$host$request_uri;
}
# ========================================
# 引入重定向配置
# ========================================
include /www/sites/www.quannengcha.com/redirect/*.conf;
}