php 切换到 SSL 后无法登录我的 wp-admin

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15238288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:52:16  来源:igfitidea点击:

Cant login to my wp-admin after switching to SSL

phpwordpressssl

提问by user1269625

I recently installed SSL certificate for my wordpress site(http to https) and now I'm unable to access Wordpress Admin. It refreshes the page and I am not logged in.

我最近为我的 wordpress 站点(http 到 https)安装了 SSL 证书,现在我无法访问 Wordpress Admin。它刷新页面,但我没有登录。

Is there something I forgot to change in my wordpress files?

我忘记更改 wordpress 文件中的某些内容了吗?

I inspected the code and the login form is pointing to my old site (the http one) and when I look at the code in the file, the form action is set to site_url() and I can't seem to find where it's defined.

我检查了代码,登录表单指向我的旧站点(http 站点),当我查看文件中的代码时,表单操作设置为 site_url() 并且我似乎无法找到它的定义位置.

回答by user3208862

I had the exact same problem with my site on NearlyFreeSpeech.net, and the solution was not so simple as fixing the site URLs. That made no difference.

我在 NearlyFreeSpeech.net 上的网站遇到了完全相同的问题,解决方案并不像修复网站 URL 那样简单。那没什么区别。

The underlying problem in my case, and the solution, were explained in the post copied below. Note that on my system, the SSL error created two problems, the one described here on Stack Overflow (wp-login refreshes without logging in) and a failure of WP to load stylesheets, which was the problem actually addressed in the forum post quoted below. The solution in the post solves bothproblems.

我的案例中的潜在问题和解决方案在下面复制的帖子中进行了解释。请注意,在我的系统上,SSL 错误造成了两个问题,一个是 Stack Overflow 上描述的问题(wp-login 刷新但未登录)和 WP 加载样式表失败,这是下面引用的论坛帖子中实际解决的问题. 帖子中的解决方案解决了这两个问题。

What you describe sounds like the browser refusing to load the stylesheet, which typically happens when first creating an HTTPS-enabled WordPress site or adding SSL/TLS to an existing WP site.

WordPress isn't very smart about "reverse proxies" like what NFSN uses, where the user hits an outer web server that then talks to an inner application server where WordPress actually lives.

If you think you have an SSL-enabled site, especially if it's a new one, this could be your problem. You would need to edit your wp-config.php file to add the following:

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';

just above the "That's all, stop editing! Happy blogging!" lines.

Conversely, if you don't think you are using SSL on your site, this won't do anything. Check the alias for your site on the NFSN site control panel. If you see a padlock, you're set up in NFSN and need the code above.

WordPress's implementation of SSL is kind of a botch. It not only doesn't recognize SSL under environments like ours - it also is prone to redirect loops if everything isn't changed in exactly the right order. If the code above causes a site outage - you keep getting complaints from the browser about redirect loops - then remove the code and ask again. I'll see if I can find my notes about how to do initial SSL setup.

您所描述的听起来像是浏览器拒绝加载样式表,这通常发生在首次创建支持 HTTPS 的 WordPress 站点或将 SSL/TLS 添加到现有 WP 站点时。

WordPress 在“反向代理”方面并不是很聪明,就像 NFSN 使用的那样,用户访问外部 Web 服务器,然后与 WordPress 实际所在的内部应用程序服务器进行通信。

如果您认为自己有一个启用 SSL 的站点,尤其是新站点,那么这可能是您的问题。您需要编辑 wp-config.php 文件以添加以下内容:

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';

就在“就是这样,停止编辑!祝博客快乐!” 线。

相反,如果您认为自己没有在您的站点上使用 SSL,那么这将无济于事。在 NFSN 站点控制面板上检查您站点的别名。如果您看到挂锁,则说明您已在 NFSN 中进行设置并需要上面的代码。

WordPress 对 SSL 的实现是一种拙劣的做法。它不仅不能在像我们这样的环境下识别 SSL - 如果所有内容都没有以完全正确的顺序更改,它也容易重定向循环。如果上面的代码导致站点中断 - 您不断收到浏览器关于重定向循环的抱怨 - 然后删除代码并再次询问。我会看看我是否能找到关于如何进行初始 SSL 设置的笔记。

回答by Emery King

You need to change the site url in wp-admin->Settings->General. Except now you need to go in through phpMyAdmin and do it manually in the wp_optionstable since you are locked out.

您需要在 wp-admin->Settings->General 中更改站点 url。除了现在您需要通过 phpMyAdmin 进入并在wp_options表中手动完成,因为您被锁定了。

You get different cookies depending on http/https so you are getting the https cookie and then being redirected to http that has no cookie because of your Wordpress settings that say what url the site resides at.

您根据 http/https 获得不同的 cookie,因此您将获得 https cookie,然后被重定向到没有 cookie 的 http,因为您的 Wordpress 设置说明了站点所在的 url。

回答by rusly

It is possible to set the site URL manually in the wp-config.php file.

可以在 wp-config.php 文件中手动设置站点 URL。

Add these two lines to your wp-config.php, where "example.com" is the correct location of your site.

将这两行添加到您的 wp-config.php,其中“example.com”是您站点的正确位置。

define('WP_HOME','https://example.com');
define('WP_SITEURL','https://example.com');

For more refer here

有关更多信息,请参阅此处

or check in table wp_optionscolumn option_name = siteurlcheck the option_value

或检查表wp_optionsoption_name = siteurl检查option_value

回答by Arianna

I have used this first:

我首先使用了这个:

i have

我有

if (
    isset($_SERVER["HTTP_X_FORWARDED_PROTO"]) && 
    $_SERVER["HTTP_X_FORWARDED_PROTO"] == "https"
) {
    $_SERVER["HTTPS"] = "on";
}

still not able to fix and nothing happened.

仍然无法修复,什么也没发生。

Then I used

然后我用

define('WP_HOME','https://example.com');
define('WP_SITEURL','https://example.com');

and I was able to connect to wp with https.

我能够使用 https 连接到 wp。

Now I have only minor issues of conflict (mixed https/http content on my page) but most things work.

现在我只有轻微的冲突问题(我的页面上混合了 https/http 内容),但大多数事情都有效。

Thank you!

谢谢!

回答by saadibabar

I went to the cpanel>filemanager and edit the file wpconfig.php inside php tags i added if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) $_SERVER['HTTPS']='on';

我去了 cpanel>filemanager 并在我添加的 php 标签中编辑文件 wpconfig.php if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) $_SERVER['HTTPS']='on ';

回答by Panayot Angarev

Go to phpadmin and find wp-options. Change siteurl and home to http. Its work :)

转到 phpadmin 并找到 wp-options。将 siteurl 和 home 更改为 http。这是工作 :)