简体   繁体   English

如何配置apache服务器以提供静态内容并将所有其他流量路由到第二个主机?

[英]How do I configure an apache server to serve static content and route all other traffic to second host?

I have Apache (2.4) running locally serving port 80 and would like it to directly serve some static content (css/js/etc). 我有Apache(2.4)在本地运行服务端口80,并希望它直接提供一些静态内容(css / js / etc)。 I have a weblogic server running on port 8007 that will serve up all the dynamic web pages. 我有一个在端口8007上运行的weblogic服务器,它将提供所有动态网页。 I would like some of the static content to be served from the Apache server directly and all other URLs to be routed to the weblogic server. 我想直接从Apache服务器提供一些静态内容,并将所有其他URL路由到weblogic服务器。 The static content and dynamic content all need to have the same context root (/myRoot). 静态内容和动态内容都需要具有相同的上下文根(/ myRoot)。 I am trying to use mod_proxy. 我正在尝试使用mod_proxy。 Here is the current relevant config in httpd.conf which I have tried (assume localhost.mydomain.com maps to 127.0.0.1): 这是httpd.conf中我当前尝试的当前相关配置(假设localhost.mydomain.com映射到127.0.0.1):

ServerName localhost.mydomain.com:80
...
ProxyRequests On
ProxyVia On
...
ProxyPass "/myRoot" "http://localhost.mydomain.com:8007/myRoot"
ProxyPassReverse "/myRoot" "http://localhost.mydomain.com:8007/myRoot"

I need the static content URL to be like this and served from Apache directly: http://localhost.mydomain.com/myRoot/static 我需要静态内容URL是这样的,并直接从Apache提供: http//localhost.mydomain.com/myRoot/static

The above configuration allows me to connect to the weblogic server running on port 8007 correctly. 上面的配置允许我正确连接到端口8007上运行的weblogic服务器。 However Im struggling to get the static content served from the Apache web server. 但是我很难获得从Apache Web服务器提供的静态内容。 I can get content from htdocs from the apache server but if I put a directory like /htdocs/myRoot/static the static content is still going to the weblogic server. 我可以从apache服务器获取htdocs的内容,但是如果我放置像/ htdocs / myRoot / static这样的目录,静态内容仍然会进入weblogic服务器。

I found this works. 我发现这个有效。 anything with /myRoot goes to the app server unless it also starts with /myRoot/enterprise/js/dojo which are all going to the htdocs directory. 使用/ myRoot的任何内容都会转到app服务器,除非它还以/ myRoot / enterprise / js / dojo开头,它们都会进入htdocs目录。 In htdocs I placed a folder /apache/htdocs/myRoot/enterprise/js/dojo. 在htdocs中我放置了一个文件夹/ apache / htdocs / myRoot / enterprise / js / dojo。

ProxyPassMatch ^/myRoot/(enterprise)/(js)/(dojo).* !
ProxyPass "/myRoot" "http://localhost.mydomain.com:8007/myRoot"
ProxyPassReverse "/myRoot" "http://localhost.ntrs.com:8007/myRoot"

Unfortunately I also found I probably need to move to using OHS rather than apache to make the webserver work with weblogic correctly so probably will have other issues setting that up =(. 不幸的是我还发现我可能需要转向使用OHS而不是apache来使webserver正确地使用weblogic,所以可能会有其他问题设置up =(。

Edit: OHS setup was easier than I though. 编辑:OHS设置比我更容易。 Had to track down some issues with server startup but then I just added this to mod_wl_ohs.conf and added dojo in the htdocs directory directly. 不得不追查服务器启动时的一些问题,但后来我把它添加到mod_wl_ohs.conf并直接在htdocs目录中添加了dojo。 below regex will match /myRoot unless it is followed by enterprise/js/dojo. 以下正则表达式将匹配/ myRoot,除非它后面是enterprise / js / dojo。 regex are confusing in OHS/Apache - the / doesnt need to be escaped for some reason so took some playing around to get the regex right. 正则表达式在OHS / Apache中令人困惑 - /不需要因为某些原因而被转义,所以需要一些游戏才能使正则表达式正确。

<IfModule weblogic_module>
    <LocationMatch "^/myRoot/((?!enterprise/js/dojo).)*$">
      WLSRequest On
      WebLogicHost localhost.mydomain.com
      WebLogicPort 8007
    </LocationMatch>      
</IfModule>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法配置Apache为CherryPy应用程序提供静态内容。 我做错了什么? - Unable to configure Apache to serve static content for CherryPy app. What I am doing wrong? 如何配置Bitnami Lightsail LAMP服务器来托管第二个网站? - How do I configure a Bitnami Lightsail LAMP server to host a second web site? 如何在AppFog中使用Apache提供静态内容(WSGI Python应用程序) - How to serve static content with Apache in AppFog (WSGI Python app) 如何使用Nginx-&gt; HAProxy-&gt; Apache在设置中提供静态内容? - How to serve static content in a setup with Nginx -> HAProxy -> Apache? 如何配置Symfony 4与其他XAMPP(Apache)项目一起路由? - How do you configure Symfony 4 to route alongside other XAMPP (Apache) projects? Apache实际上如何帮助服务大量流量? - How actually Apache help to serve large traffic? 如何在 Apache 服务器上托管 Dash 应用程序? - How do I host a Dash app on an Apache Server? Nginx / Apache服务静态内容代理 - Nginx/Apache Serve Static Content proxy 如何在Linux apache托管服务器(即,仅主机,bluehost)中使用https配置redmine - How to configure redmine with https, in linux apache hosting server (i.e just host, bluehost) 如何在不重新启动Apache Web服务器的情况下配置虚拟主机? - How can I configure Virtual Host without restarting Apache web server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM