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

Nginx同服务器部署WordPress和Yourls访问跳转异常故障求助

问题原因
  • 核心原因是Yourls站点仅配置了80端口的server块,没有对应443端口的HTTPS server块。当你使用HTTPS协议访问ys_domain.com时,Nginx在443端口找不到匹配server_name为ys_domain.com的配置,会默认将请求转发到该端口下第一个加载的server块,也就是你的WordPress站点配置,因此会跳转到WordPress。
  • 另外你给WordPress配置了80端口强制跳HTTPS的301永久重定向,如果你之前误访问过带https的ys_domain.com,或者浏览器有HSTS缓存,也会默认走HTTPS协议请求Yourls站点,触发上述匹配逻辑。
修复方案

1. 补全Yourls站点的完整配置

将Yourls的.conf配置替换为以下内容,注意替换证书路径为你实际的ys_domain.com证书存放路径:

# 80端口自动跳转HTTPS
server {
    listen   80;
    server_name www.ys_domain.com ys_domain.com;
    rewrite ^(.*) https://$server_name$1 permanent;
}

server {
    listen 443 ssl;
    server_name www.ys_domain.com ys_domain.com;
    charset utf-8;

    # 替换为你自己的ys_domain.com证书路径
    ssl_certificate /etc/nginx/ssl/ys_domain_fullchain.cer;
    ssl_certificate_key /etc/nginx/ssl/ys_domain.com.key;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
    ssl_ecdh_curve secp384r1;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    ssl_session_tickets off;
    keepalive_timeout 70;

    access_log  /var/log/nginx/ys_domain.com.access.log  main buffer=32k flush=30s;
    error_log /var/log/nginx/ys_domain.com.error.log;

    root "/var/www/YOURLS";

    location / {
        index  index.php index.html;
        try_files $uri $uri/ /yourls-loader.php$is_args$args;
    }

    location ~ ^/\.user\.ini {
            deny all;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:9100;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }
}

2. 校验配置并重载Nginx

执行以下命令校验配置语法是否正确:
nginx -t
如果返回success,执行重载命令生效:
nginx -s reload

3. 测试访问

使用浏览器无痕模式访问ys_domain.com,避免之前的301永久重定向缓存影响测试结果。

额外注意事项
  • 确认conf.d目录下的两个站点配置文件后缀均为.conf,且Nginx主配置nginx.conf中存在include /etc/nginx/conf.d/*.conf;配置项。
  • 确保Yourls的SSL证书路径填写正确,不要误用WordPress站点的证书。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 05:15:00