简体   繁体   English

Apache中的这个虚拟主机文件可能有什么问题?

[英]What could be wrong with this virtual host file in Apache?

I am trying to route an application to a sub route on an internal server, using Gunicorn with my Django app. 我正在尝试将Gunicorn与我的Django应用程序一起路由到内部服务器上的子路由。 My virtual host file looks like this: 我的虚拟主机文件如下所示:

LoadModule proxy_module /usr/lib64/apache2/mod_proxy.so
LoadModule proxy_http_module /usr/lib64/apache2/mod_proxy_http.so
<VirtualHost *:80>
        ServerName 172.16.1.81
        <Location "/mycustomapp">
            ProxyPreserveHost On
            ProxyPass http://127.0.0.1:9090
            ProxyPassReverse http://127.0.0.1:9090
        </Location>

</VirtualHost>

When I navigate to 172.16.1.81/mycustomapp , I keep getting a 404 not found error when trying to navigate to the application on that route. 导航到172.16.1.81/mycustomapp时,尝试导航到该路线上的应用程序时,始终收到404 not found错误。 Is there something else I am doing wrong here? 我在这里还做错什么吗?

Okay, I figured it out. 好吧,我知道了。 For anyone running into this type of problem in the future, the solution lies in using the ServerPath directive inside your VirtualHost configuration. 对于将来ServerPath此类问题的任何人,解决方案都在于在VirtualHost配置中使用ServerPath指令。 So for example, if you wanted to have an application be served at 172.15.1.20/app1 and another application served at 172.15.1.20/app2 (via port forwarding to a process listening on a port) the virtual host configuration would like the following: 因此,例如,如果要在172.15.1.20/app1上提供一个应用程序,并在172.15.1.20/app2上提供另一个应用程序(通过端口转发到侦听端口的进程),则虚拟主机配置将如下所示:

LoadModule proxy_module /usr/lib64/apache2/mod_proxy.so
LoadModule proxy_http_module /usr/lib64/apache2/mod_proxy_http.so
<VirtualHost *:80>
    ServerName 172.15.1.20

    ProxyPreserveHost On

    ProxyPass /app1 http://127.0.0.1:9090
    ProxyPassReverse /app1 http://127.0.0.1:9090

    ProxyPass /app2 http://127.0.0.1:9080
    ProxyPassReverse /app2 http://127.0.0.1:9080

</VirtualHost>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM