Multiples domains pointing to differents ports in apache server

后端 未结 1 1590
鱼传尺愫
鱼传尺愫 2020-12-06 23:51

I am working with a web development framework which publish its applications in apache server ports:8080, 8081, 8082, etc.

For instance MyApp1 runs in localhost:808

相关标签:
1条回答
  • 2020-12-07 00:24

    To make sure I understand what you meant: You want -

    • Client issues HTTP request to http://mydomain1.com (port 80) - then go to port 8080 on your server;
    • Client issues HTTP request to http://mydomain2.com (port 80) - then go to port 8081 on your server.

    The only reasonable way (that I know of) you can achieve this in Apache is by using what's called a Reverse Proxy, explained here: http://httpd.apache.org/docs/current/mod/mod_proxy.html

    In a nutshell: Define two name-based virtual hosts listening on port 80, each reverse-proxying requests to the "hidden" server. The two definitions would be almost exactly the same.... here's a sketch of one of them, you should be able to conclude the other one.

    <NameVirtualHost *:80>
        ServerName mydomain1.com
        ServerAlias www.domain1.com
        ... *other aliases as you wish* ...
        ProxyPass / http://localhost:8080/
        ProxyPassReverse / http://localhost:8080/
    </NameVirtualHost>
    

    The above definition causes all HTTP requests coming in on port 80, having "mydomain1.com" in their "Server path" header (that's standard behavior when someone types in a URL containing a server name; don't worry about it) or any of the mentioned aliases, to be reverse-proxied to "localhost:8080".

    Try this and let us know how it went. Good luck!

    0 讨论(0)
提交回复
热议问题