简体   繁体   中英

How can I virtually point http://example.com to http://ex2.com/example in apache server?

I am dealing with a CMS - mostly custom works. One installation of the CMS can handle more than one sites.

Now when deploying the setup on an apache server - I am facing some problems. My CMS setup is in http://ex2.com and the sites in it are like /example , /process , etc. So if I hit to http://ex2.com/example I get the first site.

My requirement is to find a way so that I can get the first site (for example) through http://example.com [ not necessarily a valid domain - it can be a virtual one ].

So using virtualhost or htaccess -- I need to point the http://example.com to http://ex2.com/example .

Is that possible? I am using apache2.4

Fixed this problem using mod_proxy and virtualhost .

In my /etc/hosts file - defined the designated virtual hostname like:

127.0.2.1   example.com www.example.com
127.0.2.2   process.com www.process.com

Then in my /etc/apache/sites-available/ex.conf file wrote the following virtual host definition:

<VirtualHost 127.0.2.1:80>
  ServerName example.com
  ServerAlias example.com www.example.com 

    <location />
        ProxyPass http://ex2.com/example/
        ProxyPassReverse http://ex2.com/example/
        Order allow,deny
        Allow from all
    </location>
</VirtualHost>


<VirtualHost 127.0.2.2:80>
  ServerName process.com
  ServerAlias process.com www.process.com 

    <location />
        ProxyPass http://ex2.com/process/
        ProxyPassReverse http://ex2.com/process/
        Order allow,deny
        Allow from all
    </location>
</VirtualHost>

And after enabling the conf file by sudo a2ensite ex command and restarting apache - Bingo! I got what I was looking for.

Thanks guys who participated in this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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