我有一个域名,例如http://example.com
。这将导致页面从 加载/var/www/example
。现在我希望所有请求都http://example.com/site2
解析到文件夹/var/www/site2
。
这是基本想法,我尝试像这样实现它(但没有成功):
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/example
DirectoryIndex /index.html index.html
#<LocationMatch "^/site2.*">
# RewriteEngine on
# RewriteRule . /example2/index.html [L]
#</LocationMatch>
AliasMatch "/site2(.*)" "/var/www/site2$1"
<Directory /var/www/site2>
Require all granted
AllowOverride all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
我尝试使用Alias
指令和LocationMatch
在到达/site2
URL 时将内容重写为正确的 URL。这是我的配置。它http://example.com/site2/
会导致index.html
来自http://example.com/
。仅当请求时http://example.com/site2/index.html
。
<VirtualHost *:80>
DocumentRoot /var/www/example
DirectoryIndex /index.html index.html
Alias "/site2" "/var/www/site2"
<Directory /var/www/site2>
Require all granted
AllowOverride all
</Directory>
</VirtualHost>
我还希望将所有 PHP 请求传递到它们自己的 FPM 池。 的请求http://example.com
应传递到fcgi://127.0.0.1:9000
, 的请求http://example.com/site2
应传递到fcgi://127.0.0.1:9001
。
我怎样才能实现这个目标?
答案1
根据“问题1)”:
您应该添加一个别名:
Alias /site2 /var/www/site2 <Directory /var/www/site2> Require all granted AllowOverride all </Directory>
该
DirectoryIndex
指令将语句读取为“绝对”文件名。我的意思是使用以下语法:DirectoryIndex /index.html index.html
DirectoryIndex
将检查index.html
位于DocumentRoot
=中的 是否/
存在,如果存在则显示,并忽略后续语句。因此,如果此记录 (/index.html
) 不是预期的,则为错误。一些这里的例子。