Subdomain under Apache to proxy into Tomcat

2019-04-14 16:38发布

I'm having trouble with making a subdomain to my Windows computer while using AJP to proxy to Tomcat. This is what I have in my httpd.conf file:

<VirtualHost *:80>  
    ServerName subdomain.localhost  
    ProxyRequests Off  
    <Proxy *>  
        Order deny,allow  
        Allow from all  
    </Proxy>  
    ProxyPass / ajp://localhost:8009/folder/  
    ProxyPassReverse / ajp://localhost:8009/folder/  
    <Location />  
        Order allow,deny  
        Allow from all  
    </Location>  
</VirtualHost>

The subdomain has been added to `c:\windows\system32\drivers\etc\hosts

127.0.0.1 localhost
127.0.0.1 subdomain.localhost

When I go to http://localhost i goes straight to the proxy. When I go to http://subdomain.localhost i goes to the proxy as well. How do I make is so the subdomain only goes to the proxy and the regular goes to Apache?

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-04-14 17:22

This should probably be moved to superuser.com but one thing to try:

<VirtualHost *:80> informs it to accept all incoming connections on port 80 to use these settings. I would try changing it to say:

<VirtualHost subdomain.localhost:80>

and see if that only applies these settings when the subdomain is used.

The ServerName tag that you put with the subdomain doesn't tell it who to listen for. The official documentation states:

The ServerName directive sets the hostname and port that the server uses to identify itself. This is used when creating redirection URLs. For example, if the name of the machine hosting the web server is simple.example.com, but the machine also has the DNS alias www.example.com and you wish the web server to be so identified, the following directive should be used:

You can read more on these configurations here.

查看更多
何必那么认真
3楼-- · 2019-04-14 17:29

You need to declare a second VirtualHost with localhost as the ServerName.

查看更多
登录 后发表回答