PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, September 21, 2022

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

 September 21, 2022     apache, django, virtualhost     No comments   

Issue

I am trying to route an application to a sub route on an internal server, using Gunicorn with my Django app. 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. Is there something else I am doing wrong here?


Solution

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. 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:

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>


Answered By - Jasonca1
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing