【问题标题】:nginx is returning 301 Moved Permanentlynginx 正在返回 301 Moved Permanently
【发布时间】:2017-02-28 23:12:02
【问题描述】:

如果我的问题与另一个问题相似,我深表歉意,但我无法找到可以帮助我解决问题的答案。 因此,在带有 ubuntu 的本地 pc 上,我已经安装并配置了 nginx + wordpress(如 stackoverflow 中所述),一切正常,但我无法从远程 pc 访问我的网站。我已经在 noip 上创建了主机名并将所有重定向到路由器,但 nginx 不断返回 301。任何帮助将不胜感激。

配置文件:

server {
        listen 80;
        listen [::]:80 default_server ipv6only=on;

        root /var/www/html;
        index index.php index.html index.htm;

        server_name localhost;

        location / {
                #try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
    }

}

curl -I mylocalwebsite.ddns.net

HTTP/1.1 301 Moved Permanently
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 19 Oct 2016 10:36:14 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.5.9-1ubuntu4.20
Set-Cookie: PHPSESSID=ku8vc501u9srdeqh08cnsdvht6; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: http://localhost/

文件:/var/log/nginx/access.log

85.105.338.54 - - [19/Oct/2016:12:38:25 +0200] "HEAD / HTTP/1.1" 301 0 "-" "curl/7.35.0"

【问题讨论】:

    标签: wordpress ubuntu nginx http-status-code-301


    【解决方案1】:

    Wordpress 在其配置中具有静态域名,如果您将其设置为 localhost,并使用 IP 或指向您的 wordpress 安装的其他域名访问它,它将重定向到 localhost。

    您是否尝试在设置中设置您的 wordpress 域名,与您的 noip 域名相同? (例如 mylocalwebsite.ddns.net)。检查您的 wordpress 设置。

    【讨论】:

      【解决方案2】:

      mylocalwebsite.ddns.net 设置为您的 server_name 指令,您的 nginx 将能够响应您对该主机的请求。

      【讨论】:

      • 也许是您的 wordpress 网站重定向到本地主机,因为您的配置中没有重定向。请看一下它的配置,看看是否设置了mylocalwebsite.ddns.net
      猜你喜欢
      • 2017-06-13
      • 2014-12-30
      • 1970-01-01
      • 1970-01-01
      • 2014-07-05
      • 1970-01-01
      • 2020-10-07
      • 1970-01-01
      • 2012-01-09
      相关资源
      最近更新 更多