【问题标题】:Nginx/.htacces redirects not working properlyNginx/.htaccess 重定向无法正常工作
【发布时间】:2018-12-12 05:38:32
【问题描述】:

我无法弄清楚我的 Nginx 虚拟主机或/和 Wordpress 重写规则出了什么问题,如下所示:

http://example.com -> https://www.example.com 有效;

http://www.example.com -> https://www.example.com 有效;

https://example.com -> https://www.example.com 根本不起作用!

我尽可能多地挖掘日志,但无济于事。

我的 Nginx 虚拟主机:

server {

# Uncomment the following line for domain mapping
# listen 443;

server_name example.com;
return 301 $scheme://www.example.com$request_uri;

root /var/www/example.com/htdocs;

index index.php index.html index.htm;

include  common/wpsc.conf;     include common/wpsubdir.conf;
include common/wpcommon.conf;
include common/locations.conf;
include /var/www/example.com/conf/nginx/*.conf;



}
server {
# Uncomment the following line for domain mapping
# listen 443;

server_name www.example.com;

root /var/www/example.com/htdocs;

index index.php index.html index.htm;

include  common/wpsc.conf;     include common/wpsubdir.conf;
include common/wpcommon.conf;
include common/locations.conf;
include /var/www/example.com/conf/nginx/*.conf;
}

我的 htaccess 重写器:

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

我使用https://easyengine.io/ 安装/配置所有内容,并从 Cpanel 迁移了我的 WordPress 网站。

我可能会错过什么?

【问题讨论】:

  • 没有看到所有这些,这是任何人的猜测! include common/wpsc.conf;include common/wpsubdir.conf;include common/wpcommon.conf;include common/locations.conf;include /var/www/example.com/conf/nginx/*.conf;
  • 你好@miknik,我怎样才能在不使线程太大的情况下将这些文件粘贴到这里?我看了看它们,没有注意到任何可能导致此问题的东西,但我还是 WP/nginx 的新手
  • 将它们粘贴到 pastebin.com 之类的地方,然后使用链接编辑您的帖子。从您到目前为止所包含的内容中,我看不到任何会导致它工作的东西。您没有 ssl 证书指令,服务器块中的监听指令被注释掉,即使它们不是,它们也没有 ssl 参数。将/etc/nginx/nginx.conf添加到我感兴趣的文件列表中。

标签: wordpress .htaccess nginx


【解决方案1】:

首先,Nginx 不支持 .htaccess 文件。

其次,很难确定为什么这不起作用,但这是我要检查的内容:

  • example.com 是否有 SSL 证书?通常重定向不会发生,如果 SSL 验证失败。
  • WordPress siteurlhome 是否设置为 https://www.example.com
  • nginx 错误日志中是否显示任何错误?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-08
    • 2013-11-04
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2018-05-18
    相关资源
    最近更新 更多