我无法使用 Apache、Django 和 SSL 在 Ubuntu 服务器上获得 wordpress 漂亮的永久链接。如果我禁用 SSL,配置工作正常,但启用它时失败。启用 SSL 后,每个 wordpress 永久链接(不映射到物理文件)都会导致 404 和 apache 错误日志中的条目,例如
File does not exist: /var/www/wpwrap/wordpress/hello-world
我已经尝试了数十种 stackoverflow 和网络建议的解决方案(绝大多数用于非 SSL 设置)- 没有任何效果。我熟悉定义 Apache 配置(但不是 wordpress)并且是这台机器的管理员。
<强>1。我的 Apache 设置
- apache2.conf
- 基本上开箱即用,不包含
<Directory>
或<VirtualHost>
条目 - 加载
conf.d/*
然后sites-enabled/*
- 基本上开箱即用,不包含
- httpd.conf(空)
启用站点/默认 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
sites enabled、conf.d 中的行,甚至是 mods-enabled 中的行,位于/etc/apache2 中的任何位置。
<强>2。服务器设置
- 预先存在的工作配置(运行一年)
- Ubuntu 12.04
- Apache 2.2.6(mpm_worker 不是 prefork)
- Django (mod_wsgi)
- Django 在/ 提供基础 url
- mod_rewrite
- 443 上的虚拟主机(mod_rewrite 将所有 80 流量推送到 443),SSL 证书
- wordpress 的新功能
- wordpress 4.2.1(与预先存在的 Django 并排运行)
- wordpress 在/blog 下提供 url
- wordpress 文件位于/var/www/wpwrap/wordpress
- mod_fastcgi 和 php-fpm
- 服务器在 worker mpm 上运行良好,因此我安装了记录良好的解决方案(php-fpm 和 mod_fastcgi)以使 PHP 与 Apache worker mpm 一起工作,而不是将 Apache 降级为 prefork mpm 仅用于 wordpress。
- wordpress 4.2.1(与预先存在的 Django 并排运行)
<强>3。什么有效:
- 没有 SSL 的漂亮永久链接(如果我只是将虚拟主机从 443 更改为 >80)
- 基于 SSL 的 Wordpress 管理界面
- 任何映射到实际存在文件的 wordpress url
- Django、SSL、现有重写
<强>4。除了上面提到的项目之外的其他尝试:
以下任何情况对 404 和错误均无影响:
- 更改虚拟主机配置的顺序(mod_wsgi 在 wordpress 之上/之下)
- 将整个 vhost 设置移动到 sites-enabled/default-ssl 并重新加载
- 玩弄 wordpress 文件的组 (www-data) 和权限 (775)
- 改变 conf.d/* 和 sites-enabled/* 的加载顺序
- 用头撞墙:-)
最佳答案
解决了。
问题是与 <Location>
冲突 block ,其中包含另一组重写规则。尽管规则不应该发生冲突(在正则表达式方面),但 Location 规则以某种方式阻止了 Directory 规则的执行,因此它们根本不会运行。
基于 Apache 文档,其中声明重写在 <Location>
中不受官方支持 block ,我迁移了所有 <Location>
重写为 <VirtualHost>
我的 conf.d/my-ssl-site.conf 文件中端口 80 和 443 的条目。现在一切正常。
关于django - WordPress 漂亮的永久链接故障转移 SSL - 404 文件不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30036112/