Apache 2.4 + FPM + Wordpress Multisite: URL Rewrite not working in admin

那年仲夏 提交于 2021-02-18 19:19:52

问题


I just moved a Wordpress multi-site from a Apache 2.4 Prefork + mod_php to a new server with Apache 2.4 Event + php-fpm.

The site is working well on the frontend and it is a lot faster then before due to the CGI, but... the Wordpress administration panel is working just for the main site (and network administration). The admin area for the second site is no more working, but the frontend is working great.

Examples

  • http://www.example.com/en/wp-admin/ => works
  • http://www.example.com/en/wp-admin/post-new.php => goes on error 404

I tried to debug the rewrites, but the unique log I have (also using Debug Level 8) is

[proxy_fcgi:error] [pid 13700:tid 140381047965440] [client X.X.X.X:54354] AH01071: Got error 'Primary script unknown\n', referer: http://www.example.com/en/wp-admin/

Follwing my configurations. Any help appreciated. Thank you.

Virtual Host

<VirtualHost *:80>
ServerName www.example.com
DocumentRoot "/srv/www/example.com/public_html"
<IfModule mpm_event_module>
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/srv/www/example.com/public_html/$1
</IfModule>
<Directory "/srv/www/example.com/public_html">
AllowOverride all
Require all granted
</Directory>
ErrorLog /srv/www/example.com/logs/error_log
TransferLog /srv/www/example.com/logs/access_log
</VirtualHost>

.htaccess

<Files "xmlrpc.php">
Order Allow,Deny
Deny from all
</Files>

# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(admin|content|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+]/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress

回答1:


Not sure if you found the solution. Just like to share our solution to this issue.

We've just added the lines below to the apache config. This will do the forwarding to FPM for all items in the regex.

ProxyPassMatch ^/([_0-9a-zA-Z-]+/)?(wp-(admin|activate|blog-header|comments-post|config|cron|links-opml|load|login|mail|settings|signup|trackback)\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$2



回答2:


I add a different solution because @parpar's one, although it is working for me, it continues to throw proxy_fcgi errors:

[proxy_fcgi:error] Got error 'Primary script unknown\n'

The solution consists in removing the ProxyPassMatch way to call PHP FPM and including a handler to manage PHP calls into the Directory environment:

<Directory "/path/to/host/root">
   # rest of configuration...
   <FilesMatch \.php$>
      SetHandler "proxy:unix:/path/to/socket.sock|fcgi://localhost"
   </FilesMatch>
</Directory>


来源:https://stackoverflow.com/questions/34698636/apache-2-4-fpm-wordpress-multisite-url-rewrite-not-working-in-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!