大网数据广告活动
服务器运维问答

Wordpress behind nginx reverse proxy doesnt work in https

· 52CE 我爱测

I'm trying to run wordpress on a docker based cloud. The setup is: There is a server running a mysql array, which serves a container with Wordpress Running on Nginx. The setup is copied from this dockerfile . The goal of this set…

问题原文

原帖链接 · Mascarpone · CC BY-SA 3.0

I'm trying to run wordpress on a docker based cloud. The setup is:

There is a server running a mysql array, which serves a container with Wordpress Running on Nginx. The setup is copied from this dockerfile. The goal of this setup is to achieve a high throughput and be compatible with our cloud setup.

The wordpress container has a local ip, in the same subnet as the mysql array and Nginx reverse proxy, and a public port to run http (not https).

The reverse proxy is configured to run SSL for the wordpress container. Navigation works on both http and https, but when I try to log in the dashboard with HTTPS, I get this error:

You do not have sufficient permissions to access this page.

The only meaningful error I found happens when I log in on the dashboard, on HTTP:

[04-Nov-2014 23:16:13 UTC] PHP Notice: Undefined index: HTTP_X_FORWARDED_PROTO in /usr/share/nginx/www/wp-config.php on line 86

but the dashboard works correctly on http.

In Wordpress configuration file I had to add the line:

/* SSL Proxy */

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

And I think this is the culprit. I found this tip in the official wordpress documentation, and without it HTTPS doesnt load the CSS, either logged or not logged. I think maybe I should modify this line to suit my configuration?

Either this, or the nginx reverse proxy configuration file, I have no idea.

The nginx configuration file in the wordpress + nginx container is quite standard, and it's copied from here.

Please help me :D

社区高分解答

原帖链接 · Mauro · CC BY-SA 3.0

I had some problem, I resolved in this way:

in my wp-config.php,

I added these lines:

if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) $_SERVER['HTTPS']='on';

BEFORE everything in the code.

Hope it helps!

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-11-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。