Ubuntu, Apache and Tomcat shared 80 ports

Source: Internet
Author: User
Tags php language tomcat tomcat server

Recently, the company is ready to do a content management system, for a variety of reasons, the website foreground using PHP language development, Web site management system using Java to develop, in the face of this situation, I am also drunk ~ ~ ~ I want the results of the site is the front desk through http://127.0.0.1 to visit, Then the entrance to the admin system is http://127.0.0.1/admin, so when Apache handles the/admin request, it forwards the request to Tomcat. After a round of degrees Niang, finally configured well, the following is my operation steps

1. Enable Proxy and Proxy_http modules

Using A2enmod to open proxy and proxy_http modules

sudo a2enmod proxy

sudo a2enmod proxy_http

2. Modify Apache configuration file

Open the Apache httpd.conf or default.conf configuration file and add the following configuration to the VirtualHost tab:

<ifmodule mod_proxy.c>
Proxyrequests off
<Proxy>
Order Deny,allow
Allow from all
</Proxy>
Proxypass/admin http://127.0.0.1:8080
Proxypassreverse/admin http://127.0.0.1:8080
</IfModule>

Save and restart Apache, then you can access the backend system via http://localhost/admin. Isn't it a very simple answer?

Here is an article I refer to:

By default, the Apache server is installed with port 80, and Tomcat uses 8080 ports, and when both are installed on one server, you want to access the JSP page provided by Tomcat, plus the following domain name: 8080, which I don't like.

The following is a simple setup that uses port 80 to access both the PHP and Tomcat-provided JSP provided by Apache. Description: The following assumes that the Apache and Tomcat Server sample domain name is installed using http://johnny.linux/(dislike localhost, custom domain name: 127.0.0.1 johnny.linux)

Host Ubuntu 14.04

Server version:apache/2.4.7 (Ubuntu)
Tomcat version:apache-tomcat-8.0.12
Set Steps

1. Enable Proxy and Proxy_http modules

Use A2enmod to open proxy and proxy_http modules (this is most convenient)

sudo a2enmod proxy
sudo a2enmod proxy_http

2. Apache Edit Virtual Host

Take my configuration for example,

apache:http//www.johnny.linux/(Alias http://johnny.linux/), tomcat:http://johnny.linux:8080/, configuration file is as follows:

cat/etc/apache2/sites-available/www.johnny.linux.conf
<virtualhost *:80>
  ServerName Www.johnny.linux
  serveralias johnny.linux

  ServerAdmin webmaster@johnny.linux
  documentroot/var/www/ HTML
</VirtualHost>

Now add a virtual host http://jsp.johnny.linux/(note that the domain name is added to the Hosts file: sudo echo "127.0.0.1 jsp.johnny.linux" >>/etc/hosts)

sudo vi/etc/apache2/sites-available/jspjohnny.linux.conf
<virtualhost *:80>
  ServerName Jsp.johnny.linux
  ServerAdmin webmaster@johnny.linux

  directoryindex index.html index.jsp documentroot
  / Opt/jvm/apache-tomcat-8.0.12/webapps/root

  proxypass/http://johnny.linux:8080/
  proxypassreverse/http:// johnny.linux:8080/
</VirtualHost>

Finally, use A2ensite to enable the virtual host and restart the APACHE2 server

sudo a2ensite www.johnny.linux.conf jsp.johnny.linux.conf
sudo service apache2 restart # or service apache2 reload

Here, you can use http://www.johnny.linux/or http://jsp.johnny.linux to access the previous content, do not have to enter 8080 in the browser's address bar





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.