-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wordpress subdirectory multisite setup can't get it to work #916
Comments
Hi @yosefy thanks for reporting this to us. We are just released a very basic implementation of URI-Rewrite to Units Router with the last release. Please share the Unit Configuration you are using so far. So basically what you are trying to do is running multiple WPs sites on a single Domain (foo.com) seperated by different directories like |
Yes I am aware of uri rewrite still couldn't manage to make it work
…On Fri, Aug 11, 2023, 1:54 PM Timo Stark ***@***.***> wrote:
Hi @yosefy <https://github.com/yosefy> thanks for reporting this to us.
We are just released a very basic implementation of URI-Rewrite to Units
Router with the last release <https://unit.nginx.org/CHANGES.txt>.
See the documentation.
https://unit.nginx.org/configuration/#uri-rewrite
So basically what you are trying to do is running multiple WPs sites on a
single Domain (foo.com) seperated by different directories like /a/ and
/b/. The Hostname configured in WP will be https://foo.com/a/ or
https://foo.com/b/? Am I getting this correct?
—
Reply to this email directly, view it on GitHub
<#916 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADCXF3KTMJXIEGDJLGITHUTXUYFM7ANCNFSM6AAAAAA3AZRYYE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
waiting for you answer. it is kind of deal breaker as for now for all the multisite i have to install nginx. which removes the whole idea of one tool doing it all. thanks btw problem not only with multisite, but also with site that has siteurl as mainsite/blog and wordpress is installed at /blog now rewrites for nginx work as expected but for unit i couldn't find working config i guess it is part of same problem thanks |
more info: so you can see that apache only overwrites SCRIPT_NAME and SCRIPT_FILENAME but when we do rewrite in unit it rewrites URI and there is no option to only change script name (we can't use variables in this field). because in wordpress there is no real file in /he/wp-admin/ but it needs to keep uri as it redirects by it to next stage when proxy with apache i see next headers: curl 'http://sitename.com/he/wp-admin/index.php' $_SERVER["USER"] == apache while in unit curl 'http://site.com/he/wp-admin/index.php'
|
Hi, @yosefy
And btw, nginx works well, right? What's the nginx's configuration? |
for nginx is like this https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/ current is is whatever you put in application config hardcoded what we need is like this: in fastcgi_params they use vars
and in nginx config
|
please pay attention to nginx rewrite rules for multisite thanks BTW for now we moving all back to php-fpm because we have lots of multisites and we will have to wait for this to be implemented |
I still can't understand the question totally. |
i have multisite with subdirectory sites so as you see in apache in my example so this: while in unit rewrite rewrites the uri i have spent lots of hours trying to config it to work if you can we can have short session so i will show you the problem thanks apache with multisite site .htaccess is :
while apache with single site config is :
in http conf there is only
|
Here's my example to minimize the question. conf.json
/tmp/scripts/wp-admin/index.php
test
Is it the same as you expected? If it's not, what's your expected value? |
Can you please share the whole SERVER array?
I need to see if it rewrites uri
That was the problem for me
…On Thu, Aug 24, 2023, 4:44 AM hongzhidao ***@***.***> wrote:
Here's my example to minimize the question.
conf.json
{
"listeners": {
"*:8080": {
"pass": "routes"
}
},
"routes": [
{
"action": {
"rewrite": "/wp-admin/",
"pass": "applications/app"
}
}
],
"applications": {
"app": {
"type": "php",
"root": "/tmp/scripts/"
}
}
}
/tmp/scripts/wp-admin/index.php
<?php
print($_SERVER['SCRIPT_FILENAME']);
test
> curl http://127.1:8080/he/wp-admin
/tmp/scripts/wp-admin/index.php
Is it the same as you expected? If it's not, what's your expected value?
Sorry I can't find the problem from nginx and apache configuration, It's
better to discuss it based on Unit configuration.
—
Reply to this email directly, view it on GitHub
<#916 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADCXF3IRFRRGETXP2MOSU7TXW2WW7ANCNFSM6AAAAAA3AZRYYE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Sure.
|
So you see we need the request uri to stay the same (with /he/)
Only script path must be rewtited
Wp uses is for it's internal redirects
That is what nginx and apache do with cgi
…On Thu, Aug 24, 2023, 4:51 AM hongzhidao ***@***.***> wrote:
Sure.
Array
(
[SERVER_SOFTWARE] => Unit/1.31.0
[SERVER_PROTOCOL] => HTTP/1.1
[PHP_SELF] => /wp-admin/index.php
[SCRIPT_NAME] => /wp-admin/index.php
[SCRIPT_FILENAME] => /tmp/scripts/wp-admin/index.php
[DOCUMENT_ROOT] => /tmp/scripts
[REQUEST_METHOD] => GET
[REQUEST_URI] => /wp-admin/
[QUERY_STRING] =>
[REMOTE_ADDR] => 127.0.0.1
[SERVER_ADDR] => 127.0.0.1
[SERVER_NAME] => 127.1
[SERVER_PORT] => 80
[HTTP_HOST] => 127.1:8080
[HTTP_USER_AGENT] => curl/7.61.1
[HTTP_ACCEPT] => */*
[REQUEST_TIME_FLOAT] => 1692841843.4071
[REQUEST_TIME] => 1692841843
)
—
Reply to this email directly, view it on GitHub
<#916 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADCXF3KIQR4FCLUM4LZ27E3XW2XRXANCNFSM6AAAAAA3AZRYYE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Do you mean |
Exactly. Like in apache example I have posted before.
…On Thu, Aug 24, 2023, 5:11 AM hongzhidao ***@***.***> wrote:
Do you mean [REQUEST_URI] should be /he/wp-admin/ rather than /wp-admin/?
—
Reply to this email directly, view it on GitHub
<#916 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADCXF3K6MDJ44PNJTY4Q673XW2Z4BANCNFSM6AAAAAA3AZRYYE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Thanks for confirming it. |
Yes nginx works ok
…On Thu, Aug 24, 2023, 5:20 AM hongzhidao ***@***.***> wrote:
Thanks for confirming it.
Does nginx work well? I didn't install Apache, but I can try it with nginx.
—
Reply to this email directly, view it on GitHub
<#916 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADCXF3NRITWESEGOIHD5HW3XW23ARANCNFSM6AAAAAA3AZRYYE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hi @yosefy, The
It's based on our internal discussion when we implemented it. We'll discuss it again internally to check which way is more reasonable.
|
Will do soon . Thanks
…On Thu, Aug 24, 2023, 6:07 AM hongzhidao ***@***.***> wrote:
Hi @yosefy <https://github.com/yosefy>,
Thanks for reporting this, good use case.
The [REQUEST_URI] is from the internal r->target, we can make it the same
as $request_uri.
In NGINX, $request_uri is constant, but in Unit, it's changeable.
All route step actions
<https://unit.nginx.org/configuration/#configuration-routes-action>
support the rewrite option that updates the URI of the incoming request
before the action is applied. It does not affect the query
<https://datatracker.ietf.org/doc/html/rfc3986#section-3.4> but changes
the uri and $request_uri variables
<https://unit.nginx.org/configuration/#configuration-variables>.
It's based on our internal discussion when we implemented it.
We'll discuss it again internally to check which way is more reasonable.
Could you try this patch to check if it can make Unit work well with your
case? It makes $request_uri constant.
That would be a good reference for us. Thanks.
diff -r de0cc10fa8b0 src/nxt_http_rewrite.c
--- a/src/nxt_http_rewrite.c Tue Aug 22 11:03:02 2023 +0100
+++ b/src/nxt_http_rewrite.c Thu Aug 24 11:02:34 2023 +0800
@@ -78,7 +78,7 @@
encoded_path.length = p - encoded_path.start;
if (r->args->length == 0) {
- r->target = encoded_path;
+ //r->target = encoded_path;
} else {
target.length = encoded_path.length + 1 + r->args->length;
@@ -92,7 +92,7 @@
*p++ = '?';
nxt_memcpy(p, r->args->start, r->args->length);
- r->target = target;
+ //r->target = target;
}
—
Reply to this email directly, view it on GitHub
<#916 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADCXF3MLEGO35JI5UK42PW3XW3AP3ANCNFSM6AAAAAA3AZRYYE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Btw, our team is busy releasing the next 1.31 version, it will be on AUG 31. |
amm took me whole day to compile thanks |
@yosefy sorry to hear that you had such a bad experience! We are aware of this and we will work on better documentation and tooling for that! |
amm after rechecking, patch is not working , still it rewrites the url |
Both And I'm wondering if making |
yes i have managed to make it work with multisite and patched version
somehow thanks
may be could be gould idea to make it optional because i guess there
are time when someone needs the opposite
thanks
…On Thu, Aug 31, 2023 at 11:24 AM hongzhidao ***@***.***> wrote:
still it rewrites the url
Both $uri and $request_uri are changeable with the official version.
The patch will make $request_uri const, but it's for testing your WP.
And I'm wondering if making $request_uri constant is the only way to meet your requirement.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Yes, and you could try the example on the unit document. |
nope
agan:
example works good for single site wp install
but not for subdirectory multisite which is also very common (less common
though :) )
…On Thu, Aug 31, 2023 at 11:36 AM hongzhidao ***@***.***> wrote:
may be could be gould idea to make it optional because i guess there
are time when someone needs the opposite
Yes, and you could try the example on the unit document.
https://unit.nginx.org/howto/wordpress/
—
Reply to this email directly, view it on GitHub
<#916 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADCXF3JQZG5VHVHC2YKEYM3XYBEHNANCNFSM6AAAAAA3AZRYYE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
i don't know why it happened with plugins.php in new config |
added like this
|
the question now.
need to test:
|
ah... and the media... |
Hi @yosefy, and Happy New Year! I took a look at some of the additional comments you left me here and discovered an additional misconfiguration issue, so thank you for these. Here's the revised configuration which now correctly works in all instances that I could find for a subdirectory multisite WordPress installation. I tested the following:
Updated config.json{
"settings": {
"http": {
"log_route": true
}
},
"listeners": {
"*:80": {
"pass": "routes"
}
},
"routes": [
{
"match": {
"uri": [
"*.ht*"
]
},
"action": {
"return": 404
}
},
{
"match": {
"uri": [
"index.php"
]
},
"action": {
"pass": "applications/wordpress/index"
}
},
{
"match": {
"uri": [
"*/wp-admin"
]
},
"action": {
"rewrite": "$uri/",
"pass": "routes"
}
},
{
"match": {
"uri": [
"~([_0-9a-zA-Z-]+\\/)(wp-(admin|includes|content)/\\.*)"
]
},
"action": {
"rewrite": "`${uri.replace(/([_0-9a-zA-Z-]+\\/)(wp-(admin|includes|content)\\/\\.*)/, '$2')}`",
"pass": "routes"
}
},
{
"match": {
"uri": [
"*.*",
"!*.php"
]
},
"action": {
"share": "/wpms$uri",
"fallback": {
"return": 404
}
}
},
{
"match": {
"uri": [
"*.php",
"*.php/*",
"*/wp-admin/",
"*/wp-admin/*/"
]
},
"action": {
"pass": "applications/wordpress/direct"
}
},
{
"action": {
"share": "/wpms$uri",
"fallback": {
"pass": "applications/wordpress/index"
}
}
}
],
"applications": {
"wordpress": {
"type": "php",
"targets": {
"direct": {
"root": "/wpms/"
},
"index": {
"root": "/wpms/",
"script": "index.php"
}
}
}
}
} A while ago you asked why I passed the request back to the routes after rewriting the request URI (stripping the subsite portion of the path) instead of directly handling it. I went back to see what actually happens in Apache. Apache has a base configuration which has things like "deny any In Unit's case, first let's rewrite the URI, and then figure out whether it's a php file, a direct call to an index.php file, an actual file that's not a php file (this would be your images / js / css files), or a directory, and depending on that we can pass it to the application directly, through the index, or try to serve the file as-is without involving php.
Yes, with the caveat that they will need two different sets of route configurations. Technically the subdir not multisite is a single site with some wp-config globals set to specific values, so they will need to work differently than a subdir multisite. That said I'm confident that the solution to the original issue with the patch that @hongzhidao provided works for correctly setting the request uri global variable. If you're happy with the solution, we can work on getting the code merged and a new version of unit published as soon as it's feasible, and once that's in, we'll close this issue. We can continue discussion about configuring Unit for WordPress in a GitHub discussions page. |
@javorszky first of all thatnks what do you say? thanks |
if i am coming to site/sub_something to route it i need to match $host and $uri but in unit we can't do && . meanding $host=x && uri=Y it is becoming route insite route.... what do you say? |
Hi,
Do you mean something like this?
In the configuration, the logic inside the
This is in our plan, we plan to support JS script conditions, for example:
|
@hongzhidao
[
{
"match": {
"host": "host1",
"uri": "/a2"
},
{
"match": {
"host": "host1",
"uri": "/a1"
},
}, ... }
in this case it will catch first one machine host without checking uri
and this is my problem because those are different blogs sitting in subdirs
…On Wed, Jan 3, 2024 at 4:43 PM hongzhidao ***@***.***> wrote:
Hi,
to route it i need to match $host and $uri
but in unit we can't do && . meanding $host=x && uri=Y
so how can i route nicely host1/a1 , host1/b1, host2/a1, host2/b1
Do you mean something like this?
[
{
"match": {
"host": "host1",
"uri": "/a1"
},
"action": {},
{
"match": {
"host": "host2",
"uri": "/a2"
},
},
...
}
In the configuration, the logic inside the match block means host ==
'...' && uri == '...'.
if we could somehow choose between OR and AND in matching rules...
This is in our plan, we plan to support JS script conditions, for example:
{
"match": {
"if": "`${host == '...' || uri == '...'}`"
}
}
—
Reply to this email directly, view it on GitHub
<#916 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADCXF3MKKVJNYABSJWFXNM3YMVU73AVCNFSM6AAAAAA3AZRYYGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZVGQ4DEOBVGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Sorry that I can't understand what you mean, for the match object.
As I understand, only the request with |
but as docs say if host1 matches , /a2 doesn't matter. because the logic is
'OR'
…On Wed, Jan 3, 2024 at 6:05 PM hongzhidao ***@***.***> wrote:
in this case it will catch first one machine host without checking uri
Sorry that I can't understand what you mean, for the match object.
"match": {
"host": "host1",
"uri": "/a2"
}
As I understand, only the request with host == host1 && uri == /a2
matches it.
—
Reply to this email directly, view it on GitHub
<#916 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADCXF3K7OVVNYPSFAT5JMFTYMV6V7AVCNFSM6AAAAAA3AZRYYGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZVGYYDKNZWHE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Could you show the related doc link or content? I found a similar rule on the document website.
|
@tippexs what is z-roadmap thanks |
Hi all, |
Previously, the REQUEST_URI within Unit could be modified, for example, during uri rewritting. We plan to make $request_uri immutable and pass constant REQUEST_URI to applications. Based on the new requirement, we remove `r->target` rewritting in the rewrite module. Closes: nginx#916
I put together a test harness and test suite to make sure that all endpoints and rewrites behave expectedly, including the rest api. That all passes, so from a functionality point of view this works as WordPress expects to work in subsite mode. There will be a writeup on the test, but I wanted to give a 👍🏻 for this issue to get it moving along 🙂 |
Previously, the REQUEST_URI within Unit could be modified, for example, during uri rewritting. We plan to make $request_uri immutable and pass constant REQUEST_URI to applications. Based on the new requirement, we remove `r->target` rewritting in the rewrite module. Closes: nginx#916
Previously, the REQUEST_URI within Unit could be modified, for example, during uri rewritting. We plan to make $request_uri immutable and pass constant REQUEST_URI to applications. Based on the new requirement, we remove `r->target` rewritting in the rewrite module. Closes: nginx#916
Previously, the REQUEST_URI within Unit could be modified, for example, during uri rewriting. We decide to make $request_uri immutable and pass constant REQUEST_URI to applications. Based on the new requirement, we remove `r->target` rewriting in the rewrite module. Closes: nginx#916
Previously, the REQUEST_URI within Unit could be modified, for example, during uri rewriting. We decide to make $request_uri immutable and pass constant REQUEST_URI to applications. Based on the new requirement, we remove `r->target` rewriting in the rewrite module. Closes: nginx#916
Previously, the REQUEST_URI within Unit could be modified, for example, during uri rewriting. We decide to make $request_uri immutable and pass constant REQUEST_URI to applications. Based on the new requirement, we remove `r->target` rewriting in the rewrite module. Closes: nginx#916 Reviewed-by: Andrew Clayton <a.clayton@nginx.com> Signed-off-by: Zhidao HONG <z.hong@f5.com>
Previously, the REQUEST_URI within Unit could be modified, for example, during uri rewriting. We decide to make $request_uri immutable and pass constant REQUEST_URI to applications. Based on the new requirement, we remove `r->target` rewriting in the rewrite module. Closes: nginx#916 Reviewed-by: Andrew Clayton <a.clayton@nginx.com> Signed-off-by: Zhidao HONG <z.hong@f5.com>
i just can't managed to get it working
examples i have are here: https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/#rewrite-rules-for-multisite-using-subdirectories
but it just won't work for unit in no way and that is sad because we can't move half of our sites
something with rewrite rules on paths like /aaa/ , /bbb/ (permalinks type)
single site wordpress works great
may be you can help with working config?
i can do the testing
i think many people still use wordpress
thanks
The text was updated successfully, but these errors were encountered: