问题描述
我在笔记本电脑的各个目录中都有不同的Web应用程序,因此我可以开始使用侦听不同端口的简单Web服务器.例如
I have different web apps in various directories on my laptop, that I can start using simple webservers listening on different ports. For example
~/app1/./app.pl
>> listening on http://localhost:3000/
~/app2/./app.pl
>> listening on http://localhost:3001/
~/app3/./app.pl
>> listening on http://localhost:3001/
我想像这样从浏览器访问以上内容
I want to access the above from my browser like so
http://localhost/app1
http://localhost/app2
http://localhost/app3
我可以使用mod_proxy进行上述操作吗?如果可以,怎么办?
Can I do the above with mod_proxy? If so, how?
更新:我必须补充说,我已经用Google搜索了mod_proxy,阅读了Apache网站上的教程,并尝试了以下方法
Update: I must add that I have Googled for mod_proxy, read the tutes on Apache's website, and experimented with the following
在我的httpd.conf
uncommented the following in my httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
在我的httpd.conf
added the following in my httpd.conf
<IfModule mod_proxy.c>
ProxyRequests On
ProxyPass /app1 http://localhost:3000/
ProxyPassReverse /app1 http://localhost:3000/
ProxyPass /app2 http://localhost:3001/
ProxyPassReverse /app2 http://localhost:3001/
ProxyPass /app3 http://localhost:3002/
ProxyPassReverse /app3 http://localhost:3002/
</IfModule>
但是,当我尝试访问上述应用时,我会收到HTTP 404.
Yet, I get HTTP 404 when I try to access the above apps.
推荐答案
我将使用mod_rewrite和mod_proxy进行此操作.例如(以下规则进入您的VirtualHost配置):
I would do this using mod_rewrite and mod_proxy. For example (the following rulesgo into your VirtualHost configuration):
RewriteEngine On
RewriteRule ^/app1(.*)$ http://localhost:3000/$1 [P]
RewriteRule ^/app2(.*)$ http://localhost:3001/$1 [P]
RewriteRule ^/app3(.*)$ http://localhost:3002/$1 [P]
这些规则使用mod_rewrite的[P]
标志来代理请求.你需要做通过添加/取消注释,确保将mod_proxy,mod_proxy_http和mod_rewrite全部加载到您的主要Apache配置中:
These rules use mod_rewrite's [P]
flag to proxy the request. You'll need to makesure that mod_proxy, mod_proxy_http and mod_rewrite are all loaded in your main apache configuration by adding/uncommenting:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so
这篇关于本地主机上通过端口80访问的不同端口上的Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!