This looks like wp-admin remove the subfolder URL but it\'s not the same problem, because the subfolder part is not a subfolder.
I\'m working on a clean VM as a host for Docker containers. I have a dockerized Wordpress listening on 8080 on the VM.
I can hit Wordpress at http://<vm_ip>:8080
and install just fine. It takes me to the backend at http://<vm_ip>:8080/wp-admin/
and everything works as expected.
Now I\'d like to access my blog at http://<vm_ip>/blog/
so I set up nginx on the VM to proxy requests per location :
upstream blog {
server localhost:8080;
}
server {
listen 80;
server_name <vm_ip> localhost;
location /blog/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Nginx-Proxy true;
proxy_pass http://blog/;
}
}
This is temporary as nginx will probably end up dockerized, but that requires custom images ; one thing at a time...
Also with an actual domain name, I would use subdomains so that would take care of my problem
I hit http://<vm_ip>/blog/
and I get to the install, but the static files\' url are not correct : http://blog/wp-includes/css/...
so the UI is a bit raw.
I move on with the install. It works and takes me to http://<vm_ip>/blog/wp-admin/install.php?step=2
but the Connect button points to http://blog/wp-login.php
so I get a 404.
I need to make a change directly in the db : site_url and home (in wp_options
) are set to http://blog
so I update them both to http://<vm_ip>/blog
.
Now the frontend works just fine, but the backend has problems. While most links are OK, some buttons\' href miss the blog part : http://<vm_ip>/wp-admin
so it takes me nowhere.
Those buttons usually have some kind of submit role :
- the close button (top left) in Appearance > Customize (points to
http://wp-admin/
) - the Save button in Settings > General (submit for
<form action="options.php">
)
What\'s funny is it\'s not consistent : the Save button on Page > Add works just fine (though it throws a DOMException : Failed to execute \'replaceState\' on \'History\': A history state object with URL \'http://blog/wp-admin/post.php?post=15&action=edit\' cannot be created in a document with origin \'http://<vm_ip>\' and URL \'http://<vm_ip>/blog/wp-admin/post.php?post=15&action=edit&message=1\'
)
Is it something with the site_url
and home
options ?
Should I search the admin templates for the incomplete urls placeholders ?
Is there some hook or filter to force the right url ?
SO网友:Manumie
我在管理模板中进行了搜索。占位符似乎依赖于函数wp_get_referer()
和wp_get_raw_referer()
哪个用途$_SERVER["REQUEST_URI"]
, $_SERVER[\'HTTP_REFERER\']
和请求中传递的wp自定义变量:$_REQUEST[\'_wp_http_referer\']
.
所以Wordpress构建了一些URL(显然不是全部)REQUEST_URI
, 那就是/wp-admin/whatever
(在后端)。日志显示wp-admin/admin-ajax.php
定期发送,因此它的URL正确。
所以我想这与nginx通过的头文件有关。
(就WP而言,这回答了我的问题。如果我需要在nginx论坛上提问,我会将其链接到这里。)
我尝试了各种重写,如果没有成功。
但我已经接近了http://<vm_ip>/wp-admin/...
请求由虚拟机上的nginx处理/
位置块,因此/blog/
位置块从未获取它们,也从未将它们代理到我的WP容器。
看来try_files
至少在一定程度上做到了:
location / {
try_files $uri /blog$uri;
}
这意味着当
/
位置捕获一个请求,它将首先尝试查找与URI匹配的文件,然后查找与URI匹配的文件
/blog
+ URI,它指向
/blog/
位置块和我的WP容器。
现在,很好,当我点击其中一个有故障的按钮时,我被重定向到我的WP容器。
胜利还没有,因为我需要重新登录。URL很奇怪:http://<vm_ip>/blog/wp-login.php?redirect_to=http%3A%2F%2Fblog%2Fwp-admin%2Foptions-general.php&reauth=1
- 如果你看看redirect_to
部分,现在是http://blog/wp-admin
...<因此,当我重新登录时,它会将我带到仪表板。
但是,表单的数据已同时保存。是的,正在取得进展!
Wordpress应该在最底层always 是否使用相同的逻辑来构建后端和前端中使用的URL?那不是某种虫子吗?