Apache从url中删除目录

我有一个运行httpd的centos服务器。 我在staging.example.com有一个网站,然后我有staging.example.com/blog或staging.example.com/wiki。 我正在博客部分工作。 这是一个WordPress的安装。 如果您转到staging.example.com/blog,则会转到blog / wp-admin / setup-config.php,如果您尝试inputstaging.example.com/blog/wp-admin,则会redirect到staging.example.com / wp-admin如果您按照链接安装wordpress,则转到staging.example.com/blog/wp-admin/core/core/core/core/core/core/core/core/core/core/core/core /core/core/core/core/core/core/core/core/core/install.php

我在/var/ww/html/example.com上提供了staging.example.com,博客位于/ var / www / html / blog wiki位于/ var / www / html / w

这是我的域特定的configuration:

NameVirtualHost staging.example.com:80 <VirtualHost *:80> ServerName staging.example.com ServerAlias staging.example.com DocumentRoot /var/www/html/example.com RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{SERVER_NAME}$1 [R,L] </VirtualHost> NameVirtualHost staging.example.com:443 <VirtualHost *:443> ServerName staging.example.com ServerAlias staging.example.com DocumentRoot /var/www/html/example.com ErrorLog /var/log/httpd/example.com/error_log CustomLog /var/log/httpd/example.com/requests.log combined ProxyPreserveHost On ProxyPass /blog http://localhost:8443 ProxyPass /wiki http://localhost:8444 # RewriteEngine On </VirtualHost> NameVirtualHost localhost:8443 <VirtualHost 127.0.0.1:8443> DocumentRoot /var/www/html/blog ErrorLog /var/log/httpd/example.com/blog/error_log CustomLog /var/log/httpd/example.com/blog/requests.log combined </VirtualHost> NameVirtualHost localhost:8444 <VirtualHost 127.0.0.1:8444> DocumentRoot /var/www/html/w ErrorLog /var/log/httpd/example.com/wiki/error_log CustomLog /var/log/httpd/example.com/wiki/requests.log combined </VirtualHost> 

是什么原因造成的?

虽然有办法做到这一点,但我发现,当反向代理所看到的path(请求URI)与源所看到的path(请求URI)相同时,事情会变得更加顺畅。 这样,如果源代码想要轻松生成工作的URL(在HTML中,在redirect等),它能够完美地生成它们,而不是简单地基于本地REQUEST_URI(和HTTP_HOST传递感谢ProxyPreserveHost ,绝对URL)。 如果反向代理引入了blog这样的path段,则必须采取特殊的步骤让Wordpress知道将blog注入到它所写的URL中,这样,URL才能通过反向代理工作(debugging时没有反向代理是有问题的)。

因此,代替ProxyPass /blog http://localhost:8443 ,请在反向代理上使用ProxyPass /blog http://localhost:8443/blog ,这意味着您的源服务器( <VirtualHost 127.0.0.1:8443> )您需要将blog目录作为DocumentRoot的子项,而不是DocumentRoot 。 例如,在/var/www/html/wp创build一个新目录,然后将您的blog目录移动到新的wp目录中,并设置DocumentRoot /var/www/html/wp 。 维基同样如此。 现在你已经到了$wgServer$wgServer的地步,而WordPress的等价物实际上是按照预期行事的。

您也将玩同样的游戏,因为您在反向代理中终止TLS,以便最终用户可以看到以https://开头的URL,而源代码中的代码未设置HTTPSvariables。 但是,这样做有点容易克服,最好是处理这个问题并保持这种方式,而不是通过执行ProxyPass https://...来堆栈TLS延迟。 基本上你需要你的反向代理在X-Forwarded-Proto: https的所有请求中添加一个HTTP头部,然后你需要你的代码(Wordpress和wiki)来观察这个头文件,并用https://...写入绝对URL。 或者跳过这个,让wp + wiki总是用https://写出URL,给定你的RewriteRule 。 如果你不这样做,你可能会看到一些混合内容的错误,例如没有CSS。