我希望我的nginx将所有不适合的内容重定向到wp-admin文件夹,或者将wp-login.php从https://重定向到http://(如果是https)。我的vhost配置只是说
server{
listen 80;
listen 443 ssl;
然后关于服务器名称,证书信息和错误页面的一些事情。任何人都可以告诉我如何强制使用http而不是https到每个不是wp-admin的文件夹以及每个不是wp-login.php的文件吗?
答案 0 :(得分:2)
我目前的解决方案是根本不重写nginx中的网址,但让Wordpress自己完成这项工作。
我的nginx配置为允许http和https,就像你的一样,所以人们可以选择他们想要的,因为我使用的CAcert证书并不是每个人都信任的。然后我将Wordpress强制登录和管理会话重定向到https,方法是将其添加到wp-config.php
:
define('FORCE_SSL_ADMIN', true);
但是,这并非将https重定向到非管理页面上的http。但这并没有多大意义,因为它没有避免证书警告:重定向只会在警告之后发生。而另一方面,有些人(例如管理员)实际上已经导入了证书,并且可能也希望使用https来使用网站的其余部分。
更多详情可在http://codex.wordpress.org/Administration_Over_SSL找到。我通过http://www.surlyjake.com/blog/2011/12/20/wordpress-https-secure-login-with-nginx/偶然发现了这个。
答案 1 :(得分:1)
在您的服务器块中,使用位置规则来匹配 / wp-admin / 和 /wp-login.php 请求并重写那些以使用 https ,以及其他所有内容 - 如果这是你想要的 - 重写使用 http 。例如:
server {
listen 80;
listen 443;
server_name your.domain.name;
# your ssl configurations here...
# example:
ssl_session_timeout 10m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
location / {
rewrite ^ http://$server_name$request_uri? last;
}
location /wp-admin/ {
rewrite ^ https://$server_name$request_uri? last;
}
location = /wp-login.php {
rewrite ^ https://$server_name$request_uri? last;
}
# your other rules here...
}