WordPress 漂亮的永久链接故障转移 SSL - 404 文件不存在
Wordpress pretty permalinks fail over SSL - 404 File does not exist
我无法使用 Apache、Django 和 SSL 在 Ubuntu 服务器上获得 wordpress 漂亮的永久链接。如果我禁用 SSL,配置工作正常,但启用它时失败。启用 SSL 后,每个 wordpress 永久链接(不映射到物理文件)都会导致 404 和 apache 错误日志中的条目,如
File does not exist: /var/www/wpwrap/wordpress/hello-world
我已经尝试了数十种 Whosebug 和网络建议的解决方案(绝大多数用于非 SSL 设置)- 没有任何效果。我熟悉定义 Apache 配置(但不是 wordpress)并且是这台机器的管理员。
1.我的 Apache 设置
- apache2.conf
- 基本上开箱即用,不包含
<Directory>
或 <VirtualHost>
条目
- 加载
conf.d/*
然后 sites-enabled/*
- httpd.conf(空)
sites-enabled/default-000
在此之前的开箱即用内容。 (下面列出的我单独的 443 虚拟主机将所有 http 流量重定向到 https,因此该文件应该没有实际意义)。为了解决此问题,我更改了此文件中的每个 <Directory>
条目以明确包含这两行。没有效果。
Options FollowSymLinks
AllowOverride All
conf.d/my-ssl-site.conf - 我的核心配置
<Location />
# preexisting, works fine
<IfModule mod_rewrite.c>
RewriteEngine on
# force www prefix for plain example.com;
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ https://www.example.com%{REQUEST_URI} [R=permanent,L]
# force ssl
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=permanent]
</IfModule>
</Location>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
ServerAdmin admin@example.com
DirectoryIndex index.html
ErrorLog "|/usr/sbin/rotatelogs -f -l /var/log/django/error.log.%Y.%m.%d 25M"
CustomLog "|/usr/sbin/rotatelogs -f -l /var/log/django/access.log.%Y.%m.%d 25M" combined
#FOR REWRITE DEBUGGING
#RewriteLogLevel 10
#RewriteLog /var/log/django/rewrites.log
# ======= RUN DJANGO/PYTHON THROUGH WSGI MODULE OF APACHE ==============
# pre-existing, works fine
WSGIScriptAlias / /path_to_my/wsgi.py
WSGIDaemonProcess example.com processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup example.com
SSLEngine on
# additional SSL config stuff snipped from here
# ==== WORDPRESS Settings
Alias /blog /var/www/wpwrap/wordpress
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
</IfModule>
<Directory /var/www/wpwrap/wordpress>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
DirectoryIndex index.php
#pretty permalink setup, as defined by wordpress Admin UI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
</Directory>
#Added these directories during wordpress troubleshooting - no effect
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
<Directory /usr/lib/cgi-bin/php5-fcgi>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
没有其他 <Directory>
配置或 <VirtualHost>
配置或 AllowOverride
站点启用的行,conf.d,甚至在启用 mods 的站点中, /etc/apache2 内的任意位置。
2。服务器设置
- 预先存在的工作配置(运行宁一年)
- Ubuntu 12.04
- Apache 2.2.6(mpm_worker 不是预分叉)
- Django (mod_wsgi)
- Django 在 /
服务基础 urls
- mod_rewrite
- 443 上的虚拟主机(mod_rewrite 将所有 80 流量推送到 443),SSL 证书
- wordpress 的新功能
- wordpress 4.2.1(运行 与预先存在的 Django 并排)
- wordpress 在 /blog
下提供 urls
- wordpress 文件位于 /var/www/wpwrap/wordpress
- mod_fastcgi 和 php-fpm
- 服务器在 worker mpm 上运行良好,所以我安装了记录良好的解决方案(php-fpm 和 mod_fastcgi)以使 PHP 与 Apache worker mpm 一起工作而不是降级 Apache为 wordpress 预分叉 mpm。
3。什么有效:
- 没有 SSL 的漂亮永久链接(如果我只是将虚拟主机从 443 更改为 >80)
- WordPress 管理员 UI 通过 SSL
- 映射到实际存在文件的任何 wordpress url
- Django、SSL、现有重写
4.除了上面提到的项目之外的其他尝试:
对 404 和错误没有任何影响:
- 更改虚拟主机配置的顺序(mod_wsgi above/below wordpress)
- 将整个 vhost 设置移动到 sites-enabled/default-ssl 并重新加载
- 使用 wordpress 文件的组 (www-data) 和权限 (775)
- 正在更改 conf.d/* 和启用站点/*
的加载顺序
- 用头撞墙:-)
解决了。
问题是与包含另一组重写规则的 <Location>
块发生冲突。尽管规则不应该发生冲突(在正则表达式方面),但 Location 规则以某种方式阻止了 Directory 规则的执行,因此它们根本不会 运行。
基于 Apache 文档,其中指出 <Location>
块中不正式支持重写,我将所有 <Location>
重写迁移到我的 conf 中端口 80 和 443 的 <VirtualHost>
条目中。 d/my-ssl-site.conf 文件。现在一切正常。
我有所有相同的症状,发现是虚拟主机中的 SSL 块 /etc/apache2/sites-available/mysite.com.conf
<VirtualHost _default_:443>
缺少目录块...
<Directory /var/www/html/mysite.com/public_html/>
Options -Indexes +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
一旦我拥有主页上的所有永久链接就开始工作:)
我无法使用 Apache、Django 和 SSL 在 Ubuntu 服务器上获得 wordpress 漂亮的永久链接。如果我禁用 SSL,配置工作正常,但启用它时失败。启用 SSL 后,每个 wordpress 永久链接(不映射到物理文件)都会导致 404 和 apache 错误日志中的条目,如
File does not exist: /var/www/wpwrap/wordpress/hello-world
我已经尝试了数十种 Whosebug 和网络建议的解决方案(绝大多数用于非 SSL 设置)- 没有任何效果。我熟悉定义 Apache 配置(但不是 wordpress)并且是这台机器的管理员。
1.我的 Apache 设置
- apache2.conf
- 基本上开箱即用,不包含
<Directory>
或<VirtualHost>
条目 - 加载
conf.d/*
然后sites-enabled/*
- 基本上开箱即用,不包含
- httpd.conf(空)
sites-enabled/default-000
在此之前的开箱即用内容。 (下面列出的我单独的 443 虚拟主机将所有 http 流量重定向到 https,因此该文件应该没有实际意义)。为了解决此问题,我更改了此文件中的每个
<Directory>
条目以明确包含这两行。没有效果。Options FollowSymLinks AllowOverride All
conf.d/my-ssl-site.conf - 我的核心配置
<Location /> # preexisting, works fine <IfModule mod_rewrite.c> RewriteEngine on # force www prefix for plain example.com; RewriteCond %{HTTP_HOST} ^example\.com RewriteRule ^(.*)$ https://www.example.com%{REQUEST_URI} [R=permanent,L] # force ssl RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=permanent] </IfModule> </Location> <VirtualHost *:443> ServerName example.com ServerAlias www.example.com ServerAdmin admin@example.com DirectoryIndex index.html ErrorLog "|/usr/sbin/rotatelogs -f -l /var/log/django/error.log.%Y.%m.%d 25M" CustomLog "|/usr/sbin/rotatelogs -f -l /var/log/django/access.log.%Y.%m.%d 25M" combined #FOR REWRITE DEBUGGING #RewriteLogLevel 10 #RewriteLog /var/log/django/rewrites.log # ======= RUN DJANGO/PYTHON THROUGH WSGI MODULE OF APACHE ============== # pre-existing, works fine WSGIScriptAlias / /path_to_my/wsgi.py WSGIDaemonProcess example.com processes=2 threads=15 display-name=%{GROUP} WSGIProcessGroup example.com SSLEngine on # additional SSL config stuff snipped from here # ==== WORDPRESS Settings Alias /blog /var/www/wpwrap/wordpress <IfModule mod_fastcgi.c> AddHandler php5-fcgi .php Action php5-fcgi /php5-fcgi Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization </IfModule> <Directory /var/www/wpwrap/wordpress> Options FollowSymLinks AllowOverride All Order allow,deny Allow from all DirectoryIndex index.php #pretty permalink setup, as defined by wordpress Admin UI <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /blog/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /blog/index.php [L] </IfModule> </Directory> #Added these directories during wordpress troubleshooting - no effect <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> <Directory /usr/lib/cgi-bin/php5-fcgi> Options FollowSymLinks AllowOverride All </Directory> </VirtualHost>
没有其他
<Directory>
配置或<VirtualHost>
配置或AllowOverride
站点启用的行,conf.d,甚至在启用 mods 的站点中, /etc/apache2 内的任意位置。
2。服务器设置
- 预先存在的工作配置(运行宁一年)
- Ubuntu 12.04
- Apache 2.2.6(mpm_worker 不是预分叉)
- Django (mod_wsgi)
- Django 在 / 服务基础 urls
- mod_rewrite
- 443 上的虚拟主机(mod_rewrite 将所有 80 流量推送到 443),SSL 证书
- wordpress 的新功能
- wordpress 4.2.1(运行 与预先存在的 Django 并排)
- wordpress 在 /blog 下提供 urls
- wordpress 文件位于 /var/www/wpwrap/wordpress
- mod_fastcgi 和 php-fpm
- 服务器在 worker mpm 上运行良好,所以我安装了记录良好的解决方案(php-fpm 和 mod_fastcgi)以使 PHP 与 Apache worker mpm 一起工作而不是降级 Apache为 wordpress 预分叉 mpm。
- wordpress 4.2.1(运行 与预先存在的 Django 并排)
3。什么有效:
- 没有 SSL 的漂亮永久链接(如果我只是将虚拟主机从 443 更改为 >80)
- WordPress 管理员 UI 通过 SSL
- 映射到实际存在文件的任何 wordpress url
- Django、SSL、现有重写
4.除了上面提到的项目之外的其他尝试:
对 404 和错误没有任何影响:
- 更改虚拟主机配置的顺序(mod_wsgi above/below wordpress)
- 将整个 vhost 设置移动到 sites-enabled/default-ssl 并重新加载
- 使用 wordpress 文件的组 (www-data) 和权限 (775)
- 正在更改 conf.d/* 和启用站点/* 的加载顺序
- 用头撞墙:-)
解决了。
问题是与包含另一组重写规则的 <Location>
块发生冲突。尽管规则不应该发生冲突(在正则表达式方面),但 Location 规则以某种方式阻止了 Directory 规则的执行,因此它们根本不会 运行。
基于 Apache 文档,其中指出 <Location>
块中不正式支持重写,我将所有 <Location>
重写迁移到我的 conf 中端口 80 和 443 的 <VirtualHost>
条目中。 d/my-ssl-site.conf 文件。现在一切正常。
我有所有相同的症状,发现是虚拟主机中的 SSL 块 /etc/apache2/sites-available/mysite.com.conf
<VirtualHost _default_:443>
缺少目录块...
<Directory /var/www/html/mysite.com/public_html/>
Options -Indexes +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
一旦我拥有主页上的所有永久链接就开始工作:)