【问题标题】:nginx returning 301 without any rewritenginx返回301而没有任何重写
【发布时间】:2022-06-23 18:31:45
【问题描述】:

我有一个 wordpress 网站,配置如下:

ian@ianhobson:/etc/nginx/sites-enabled$ cat thecoachmasternetwork
# Statements for thecoachmasternetwork.com
#
# rewrites of http to https at bottom of file
server {

server_name thecoachmasternetwork.com www.thecoachmasternetwork.com;

listen 80;
fastcgi_read_timeout  300;

root /var/www/thecoachmasternetwork/htsecure;
index index.php;
fastcgi_index index.php;

access_log /var/log/nginx/thecoachmasternetwork.access.log;
# error_log  /var/log/nginx/error.log;
#
location = /favicon.ico {
    log_not_found off;
    access_log off;
}
location ~ \.user\.ini$ {
    deny all;
}
# disallow hot linking to images
location ~ .(gif|png|jpg|jpeg)$ {
    valid_referers none blocked thecoachmasternetwork.com www.thecoachmasternetwork.com;
    if ($invalid_referer) {
        return 403;
    }
}
# serve static files that exist
location / {
    try_files $uri $uri/ /index.php?$args;
}
# send .php files to fastcgi if file exists
location ~ \.php$ {
   # Zero-day exploit defence - http://forum.nginx.org/read.php?2,88845,page=3
   try_files $uri =404;
   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   fastcgi_param SCRIPT_FILENAME $document_root@fastcgi_script_name;
   fastcgi_param PATH_INFO       $fastcgi_path_info;
   include /etc/nginx/fastcgi.conf;
   fastcgi_pass 127.0.0.1:9000;


 }

}

    # redirects from http -> https
    #server {
    #    if ($host = www.thecoachmasternetwork.com) {
    #        return 301 https://$host$request_uri;
    #    } # managed by Certbot
    
    
    #    if ($host = thecoachmasternetwork.com) {
    #        return 301 https://$host$request_uri;
    #    } # managed by Certbot
    
    
    #    server_name thecoachmasternetwork.com www.thecoachmasternetwork.com;
    #    listen 80;
    #    return 404; # managed by Certbot
    
    #}
    ian@ianhobson:/etc/nginx/sites-enabled$

我找不到重写或返回 301。

但是,当我请求根目录或请求 /index.php 时,访问日志显示 301 重定向到我服务器上的另一个站点。这不是 default_site,也不是第一个站点。在包含启用站点/*之前,这些已在 nginx.conf 中设置。但是仅在端口 80 上。

我怀疑是 certbot 的证书有问题,(这就是我将它切换到端口 80 的原因,所以我可以重新启动它们)。重定向到的站点在 https 上,并且看起来很好。

其他可能有用的信息。 /license.txt 已正确提供。包含 的 .php 文件会产生预期的结果。我看不出有什么奇怪的。我翻遍了 WP 文件,并没有发现任何奇怪的地方,但它是一个极其复杂的网站。

error.log 中没有任何内容。

那么发生了什么?

【问题讨论】:

    标签: php wordpress nginx


    【解决方案1】:

    原来 wordpress 在 ???options 表中有两行,它们定义了 siteurl 和主页的 URL。我没有更改这些,是 wordpress 发布了 301。

    【讨论】:

      猜你喜欢
      • 2015-07-21
      • 1970-01-01
      • 2020-06-07
      • 1970-01-01
      • 1970-01-01
      • 2012-02-27
      • 2019-01-11
      • 2017-02-28
      • 2021-08-04
      相关资源
      最近更新 更多