有人用 wordpress 吗,能帮忙说说我不能正确调用 https 资源是什么原因?

2014-07-06 12:10:16 +08:00
 yangzh
ssl 证书已经正确部署。比如说直接访问 https://example.com/wp-content/themes/twentytwelve/style.css 是没有问题的,浏览器绿色小锁什么的应有尽有。

settings 里面的 WordPress Address (URL) 和 Site Address (URL) 都已经设置为 https://example.com

但是直接访问 https://example.com,网站是很多资源载入不正确的。具体来说,打开源代码,所有<link>资源都是 http 的!比如说style.css <link rel=stylesheet href="http://example.com/wp-content/themes/twentytwelve/style.css">

吊诡的是,主题文件的 header 是这样子引入各种 css js 的: <link rel=stylesheet href="<?php echo get_template_directory_uri(); ?>/style.css">

难道 wordpress 不是会根据使用的 protocol 或者 WordPress Address Site Address 从而在各种函数中返回 ‘https’ 的吗???!!!

求助可能出现了什么问题?我觉得要可能是某些 wordpress 设置问题。
5113 次点击
所在节点    问与答
14 条回复
yangqi
2014-07-06 12:14:48 +08:00
装了缓存插件没?
yangzh
2014-07-06 12:20:18 +08:00
@yangqi 刷新了。
yangzh
2014-07-06 12:32:13 +08:00
好像还是不能 append。我这里追加评论。
用的是 lnmpa 的模式:前 nginx -> 后 apache 那样。

我在php 文件中加入一句 <?php echo $_SERVER['SERVER_PORT']; ?>,即使在 https 网址访问这个 php 文件, echo 出来的端口依然是 80。估计这就是 wordpress 不能自动转换 https 的原因了。我猜测是 nginx 的配置有问题。有没有哪位大神指出 nginx 怎样配置才对啊。

nginx 的与 apache 有关的 server 段:
server{
#...
location / {
try_files $uri @apache;
}

location @apache {
internal;
proxy_pass http://127.0.0.1:88;
include proxy.conf;
}

location ~ [^/]\.php(/|$)
{
proxy_pass http://127.0.0.1:88;
include proxy.conf;
}
}
yangqi
2014-07-06 12:41:37 +08:00
那肯定是nginx没配置好了

https的配置基本和http的一样, 除了证书部分, 你给出的server是http还是https的?
ovear
2014-07-06 12:51:24 +08:00
@yangzh 你的proxy_pass需要改为https才能让php判断到你是以https方式访问。
yangzh
2014-07-06 13:14:58 +08:00
@yangqi
listen 443 ssl;


@ovear

试试
yangzh
2014-07-06 13:17:17 +08:00
@ovear

proxy_pass https://127.0.0.1:88; 会导致 502 哦。apache 要怎样配置?
yangzh
2014-07-06 13:18:38 +08:00
@yangqi
nginx配置的证书肯定是好的。直接访问 https://example.com/wp-content/themes/twentytwelve/style.css 是没有问题的,浏览器绿色小锁什么的应有尽有。
就是什么 https http 等信息 php 或 apache 不能正确获取。
ovear
2014-07-06 15:25:23 +08:00
@yangzh 后端apache要开启https
zhouzb889
2014-07-06 18:38:57 +08:00
yangzh
2014-07-06 19:19:46 +08:00
@zhouzb889 无关这个
panlilu
2014-07-06 19:21:56 +08:00
试一下把设置-常规选项里面的两个地址改成https打头的地址
yangzh
2014-07-06 19:38:58 +08:00
@panlilu 设置了
soome
2014-08-16 00:05:11 +08:00
同是lnmpa的。
最近在弄ssl的问题,百思不得其姐。
看了很多文章,用下面的配置,已经接近完全成功。

nginx配置一个443的server,一个80的server(我这个用来强制跳转到https)。

nginx的配置文件:

server
{
listen 443;
#listen [::]:80;
server_name ca.net www.ca.net;
index index.html index.htm index.php default.html default.htm default.php;
root /home/xxxxx/xxxxx;

ssl on;
ssl_certificate crt; #修改具体文件
ssl_certificate_key key; #修改具体文件
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers RC4:HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
keepalive_timeout 60;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

location / {
try_files $uri @apache;
}

location @apache {
internal;
proxy_pass http://127.0.0.1:88;
include proxy.conf;
}

location ~ [^/]\.php(/|$)
{
proxy_pass http://127.0.0.1:88;
include proxy.conf;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*\.(js|css)?$
{
expires 12h;
}

access_log off;
}
server {
listen 80;
server_name sinoca.net www.sca.net;
rewrite ^/(.*) https://www.ca.net/$1 permanent;
}


apache要怎么弄?
默认不设置的话,混合内容直接被chrome和火狐过滤掉。也就是引入的http链接的css,js等不会加载,网页框架就不正常了。

apache也需要开启ssl。

apache配置文件:
<VirtualHost *:88>
ServerAdmin webmaster@example.com
php_admin_value open_basedir "/xxxx/xxxx/xxxx:/tmp/:/var/tmp/:/proc/"
DocumentRoot "/xxxx/xxxx/xxxx"
ServerName ca.net
ServerAlias www.ca.net
#SSL Engine Switch:
#Enable/Disable SSL for this virtual host.
SSLEngine on

# Server Private Key:
# If the key is not combined with the certificate, use this
# directive to point at the key file. Keep in mind that if
# you've both a RSA and a DSA private key you can configure
# both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateFile ".crt"
SSLCertificateKeyFile "/usr/.......key"
#ErrorLog "logs/-error_log"
#CustomLog "logs/-access_log" common
</VirtualHost>

重启服务就可以解决大部分问题了。主题和wordpress自带的css以及js这时候都是https链接了。
因为wordpress的主题和插件太随意,还是有部分资源以http开头,这个需要自己去修改了。
这些资源多半是设置的绝对链接。

http://v2.freep.cn/3tb_14081523585682cu512293.png


目前的疑问是,apache(2.2.27)是否支持单ip多证书的问题,有知道的么?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/121181

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX