admin管理员组文章数量:1125298
First off my server is sitting behind a load balancer. My SSL certificate sits on the load balancer and handles HTTPS. The data coming in on port 443 is forwarded to the Wordpress server using HTTP on port 80.
However, wordpress and php do not know my server configuration. This causes the browser to get suspicious about the validity of my valid SSL certificate.
To fix this I added the following code to functions.php. I found this code here and the codex agrees.
/**
* Make PHP HTTPS aware via HTTP_X_FORWARDED_PROTO
*/
if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS']='on';
}
This works great for the frontend, but now the /wp-admin/ is inaccessible even with my Admin account. After logging in I receive a message, "Sorry, you are not allowed to access this page." No other help is provided.
So I searched through the wp-admin folder and discovered that the words "Sorry, you are not allowed to access this page." appear 17 different times.
Most of these error messages are associated with a user permissions check.
How do I keep HTTPS 'on' and retain admin access?
Summary:
- Before adding HTTP_X_FORWARDED_PROTO logic to functions.php I can access wp-admin/
- After adding HTTP_X_FORWARDED_PROTO logic to functions.php I cannot access wp-admin/
- After removing HTTP_X_FORWARDED_PROTO logic to functions.php I cannot access wp-admin/
UPDATE:
I've discovered that the error message is coming from wp-admin/menu.php and this chunk of code at the bottom. I added menu.php
to the end of the error to figure out that it was this file.
if ( !user_can_access_admin_page() ) {
/**
* Fires when access to an admin page is denied.
*
* @since 2.5.0
*/
do_action( 'admin_page_access_denied' );
wp_die( __( 'Sorry, you are not allowed to access this page. menu.php'), 403 );
}
I still do not understand how to fix this.
First off my server is sitting behind a load balancer. My SSL certificate sits on the load balancer and handles HTTPS. The data coming in on port 443 is forwarded to the Wordpress server using HTTP on port 80.
However, wordpress and php do not know my server configuration. This causes the browser to get suspicious about the validity of my valid SSL certificate.
To fix this I added the following code to functions.php. I found this code here and the codex agrees.
/**
* Make PHP HTTPS aware via HTTP_X_FORWARDED_PROTO
*/
if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS']='on';
}
This works great for the frontend, but now the /wp-admin/ is inaccessible even with my Admin account. After logging in I receive a message, "Sorry, you are not allowed to access this page." No other help is provided.
So I searched through the wp-admin folder and discovered that the words "Sorry, you are not allowed to access this page." appear 17 different times.
Most of these error messages are associated with a user permissions check.
How do I keep HTTPS 'on' and retain admin access?
Summary:
- Before adding HTTP_X_FORWARDED_PROTO logic to functions.php I can access wp-admin/
- After adding HTTP_X_FORWARDED_PROTO logic to functions.php I cannot access wp-admin/
- After removing HTTP_X_FORWARDED_PROTO logic to functions.php I cannot access wp-admin/
UPDATE:
I've discovered that the error message is coming from wp-admin/menu.php and this chunk of code at the bottom. I added menu.php
to the end of the error to figure out that it was this file.
if ( !user_can_access_admin_page() ) {
/**
* Fires when access to an admin page is denied.
*
* @since 2.5.0
*/
do_action( 'admin_page_access_denied' );
wp_die( __( 'Sorry, you are not allowed to access this page. menu.php'), 403 );
}
I still do not understand how to fix this.
Share Improve this question edited Dec 23, 2016 at 20:46 nu everest asked Dec 23, 2016 at 20:20 nu everestnu everest 6331 gold badge8 silver badges17 bronze badges 3 |1 Answer
Reset to default 28Special thanks to user42826.
According to the codex:
If WordPress is hosted behind a reverse proxy that provides SSL, but is hosted itself without SSL, these options will initially send any requests into an infinite redirect loop. To avoid this, you may configure WordPress to recognize the HTTP_X_FORWARDED_PROTO header (assuming you have properly configured the reverse proxy to set that header).
The following actions will solve the problem.
Before require_once( ABSPATH . 'wp-settings.php' );
, add this to wp-config.php. (codex reference)
/* SSL Settings */
define('FORCE_SSL_ADMIN', true);
/* Turn HTTPS 'on' if HTTP_X_FORWARDED_PROTO matches 'https' */
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
$_SERVER['HTTPS'] = 'on';
}
Remove this from functions.php as it is unnecessary.
/**
* Make PHP HTTPS aware via HTTP_X_FORWARDED_PROTO
*/
if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS']='on';
}
本文标签: phpSetting SERVER39HTTPS3939on39 prevents access to wpadmin
版权声明:本文标题:php - Setting $_SERVER['HTTPS']='on' prevents access to wp-admin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736635501a1945869.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
define('FORCE_SSL_ADMIN', true);
– user42826 Commented Dec 23, 2016 at 21:57