从虚拟主机proxypass中排除别名
•浏览 1
Exclude an alias from virtualhost proxypass
我正在关注虚拟主机配置。期望的结果是:
- 如果有人请求 http://test.myserver.com/myapp,apache 服务
他来自 /var/www/myapp
- 如果 http://test.myserver.com/ 是
请求后,apache 将其重定向到端口 8069。
第 2 次有效,但第 1 次无效。有人可以帮忙吗!
<VirtualHost *:80>
ServerName test.myserver.com
Alias /myapp /var/www/myapp
<Directory /var/www/myapp>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ProxyPass / http://localhost:8069/
ProxyPassReverse / http://localhost:8069/
</VirtualHost><VirtualHost *:80>
ServerName test.myserver.com
Alias /myapp /var/www/myapp
<Directory /var/www/myapp>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ProxyPassMatch ^/myapp !
ProxyPass / http://localhost:8069/
ProxyPassReverse / http://localhost:8069/
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>
ProxyPass /myapp !
ProxyPass / http://localhost:8069/<Location /.well-known/acme-challenge/>
RewriteEngine off
ProxyPass !
</Location>
这就是我能够达到预期结果的方式。以下是 ProxyPassMatch ^/myapp ! 发挥作用的工作配置,除了 (server-address)/myapp 之外,所有请求都被代理到在端口 8069 上运行的 open-erp 的另一台服务器:
<VirtualHost *:80>
ServerName test.myserver.com
Alias /myapp /var/www/myapp
<Directory /var/www/myapp>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ProxyPass / http://localhost:8069/
ProxyPassReverse / http://localhost:8069/
</VirtualHost><VirtualHost *:80>
ServerName test.myserver.com
Alias /myapp /var/www/myapp
<Directory /var/www/myapp>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ProxyPassMatch ^/myapp !
ProxyPass / http://localhost:8069/
ProxyPassReverse / http://localhost:8069/
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>
ProxyPass /myapp !
ProxyPass / http://localhost:8069/<Location /.well-known/acme-challenge/>
RewriteEngine off
ProxyPass !
</Location>
您可以简单地在定义 / 之前添加另一个 ProxyPass 指令,而不是使用:ProxyPassMatch ^/myapp !,如下所示:
<VirtualHost *:80>
ServerName test.myserver.com
Alias /myapp /var/www/myapp
<Directory /var/www/myapp>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ProxyPass / http://localhost:8069/
ProxyPassReverse / http://localhost:8069/
</VirtualHost><VirtualHost *:80>
ServerName test.myserver.com
Alias /myapp /var/www/myapp
<Directory /var/www/myapp>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ProxyPassMatch ^/myapp !
ProxyPass / http://localhost:8069/
ProxyPassReverse / http://localhost:8069/
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>
ProxyPass /myapp !
ProxyPass / http://localhost:8069/<Location /.well-known/acme-challenge/>
RewriteEngine off
ProxyPass !
</Location>
由于 ProxyPass 尊重优先级(将处理第一个匹配项),它将正确重定向到目录而不是代理。
如果你有一个 RewriteCond(很可能在你运行代理时),这个也会让你开心!
<VirtualHost *:80>
ServerName test.myserver.com
Alias /myapp /var/www/myapp
<Directory /var/www/myapp>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ProxyPass / http://localhost:8069/
ProxyPassReverse / http://localhost:8069/
</VirtualHost><VirtualHost *:80>
ServerName test.myserver.com
Alias /myapp /var/www/myapp
<Directory /var/www/myapp>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ProxyPassMatch ^/myapp !
ProxyPass / http://localhost:8069/
ProxyPassReverse / http://localhost:8069/
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>
ProxyPass /myapp !
ProxyPass / http://localhost:8069/<Location /.well-known/acme-challenge/>
RewriteEngine off
ProxyPass !
</Location>