You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nginx运行正常但间歇性服务,域名频繁显示服务商广告求助

部署Django+Gunicorn+Nginx时域名间歇性跳转服务商广告页的问题排查

问题现象

尝试通过Django、Gunicorn和Nginx部署静态HTML页面时出现异常:

  • 域名频繁显示域名服务商广告页而非目标页面,服务短暂正常后自行中断,无操作时也会出现正常服务后立刻失效的情况
  • 已禁用浏览器缓存并使用隐私窗口访问,存在www域名正常而非www异常、反之亦然的现象

相关配置文件

nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
#
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

sites-available/example.com 原配置

server {
    listen 80;
    listen [::]:80;
    server_name www.example.com example.com;
    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /root/example/project/staticfiles;
    }
    location / {
        include proxy_params;
        proxy_pass http://unix:/var/sockets/gunicorn.sock;
    }
}

测试用简化配置

server {
    server_name example.com www.example.com;

    return 200 "it works";
}

已完成的排查操作

  • 检查Nginx错误日志:sudo cat /var/log/nginx/error.log无报错
  • 验证Nginx配置:sudo nginx -t显示配置文件正常
  • 查看服务状态:systemctl status nginx和Gunicorn服务均显示已启用且运行中
  • 简化配置测试:替换为返回固定文本的配置并重启Nginx,问题未改善
  • 检查Gunicorn日志:cat /var/log/gunicorn/error.log无报错,重启Gunicorn无效
  • 端口监听检查:
    • netstat -tulpen | grep 80显示80、443端口均处于监听状态
    • lsof -i -n | fgrep nginx确认Nginx监听http/https端口,且存在已建立的连接
  • 本地请求测试:
    • curl -I https://example.com返回正常200响应
    • curl -I http://www.example.com返回预期的301重定向
  • 防火墙状态:ufw status显示未启用;重启服务器后问题仍存在

服务器环境:DigitalOcean VPS,Ubuntu 23.10;SSL证书由Certbot生成,服务正常时证书有效。

排查方向建议

  • DNS解析异常
    • 检查域名A/AAAA记录是否存在解析波动,确认是否同时指向服务商广告IP和VPS IP
    • 使用不同公共DNS服务器(如8.8.8.8、1.1.1.1)测试解析结果,验证是否存在解析不一致的情况
    • 登录域名管理后台,检查是否开启了隐性URL转发/跳转功能,部分服务商在解析异常时会强制跳转至广告页,需关闭该功能
  • 网络链路问题
    • 使用mtr example.com或持续ping命令监测VPS网络的丢包和延迟情况,排查链路稳定性
    • 查看DigitalOcean后台的VPS监控面板,确认是否存在网络异常,必要时提交工单咨询
  • Nginx配置干扰
    • 确认sites-available的配置文件已正确软链接到sites-enabled目录,执行ls -l /etc/nginx/sites-enabled/检查
    • 检查是否存在默认配置文件(如default.conf)干扰,可暂时重命名默认配置后重启Nginx测试
  • 域名服务商侧限制
    • 确认域名已完成实名认证、备案(若有要求),部分服务商未完成时会强制跳转广告
    • 检查域名的DNS服务器是否设置为自定义DNS(如DigitalOcean DNS),避免使用服务商默认DNS导致劫持

内容的提问来源于stack exchange,提问作者tonyd629

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 08:15:54