Ubuntu 14.04+apache Reverse proxy settings

Source: Internet
Author: User
Tags http redirect

The first step

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer

Step Two

In Ubuntu Apache, each site's configuration file is placed in a separate file, find the corresponding files in the Sites-available folder and modify, the modified configuration file is almost the following look.
ServerName www.a.com
DocumentRoot "/var/site/www/"
Proxyrequests OFF
<proxy *>
Order Deny,allow
Allow from all
</Proxy>
proxypass/http://host.com/
proxypassreverse/http://host.com/

Proxyrequests is the type of proxy, if it is on it represents the forward proxy, we need to reverse proxy, set to OFF. proxypassreverse/http://host.com/It means that all requests from the root directory are proxied to the root directory of the http://host.com/.

Step Three

Restart Apache Service

Service Apache Restart

Here, say something.an overview of Proxypass and Proxypassreverse and Proxypassmatch

1, Proxypass:

Syntax: proxypass [path]!| Url

It is mainly used as a URL prefix match, cannot have a regular expression , it is configured within the path is actually a virtual path, after the reverse proxy to the back-end URL,path is not brought past , using the example:

1), proxypass/images/!

This example indicates that the/images/request is not forwarded.

2), proxypass/mirror/foo/http://backend.example.com/

We assume that the current service address is http://example.com/, if we make the following request:

Http://example.com/mirror/foo/bar

That will be turned into an internal request:

Http://backend.example.com/bar

Note: When configured, you do not need a forwarded request to be configured in front of the request that needs to be forwarded.


2, Proxypassmatch:

syntax: proxypassmatch [regex]!| URL

This is actually a URL regular match , rather than a simple prefix match, the regex portion of the match is taken to the backend URL, which is different from Proxypass. Examples of Use:

1, Proxypassmatch ^/images!

This example indicates that a request to/images will not be forwarded.

2, Proxypassmatch ^ (/.*\.gif) $ http://backend.example.com$1

This example indicates that requests for all GIF images are forwarded to the backend, such as request http://example.com/foo/bar.gif at this time, and the internal will be converted to such request http://backend.example.com/foo/bar.gif.


3, Proxypassreverse

Syntax: proxypassreverse [path] url

It is generally used in conjunction with the PROXYPASS directive, which enables Apache to adjust the URL of the location, content-location, and URI header in the HTTP redirect response, which avoids the use of Apache as a reverse proxy. HTTP redirection of the backend server caused the problem of bypassing the reverse proxy. See the following example:

Proxypass/example http://www.example.com/
Proxypassreverse/example http://www.example.com/

Proxypassreverse's role is to reverse proxy, if not add such a reverse proxy setting, access to http://www.test.com/example/a, If www.example.com redirect the request to http://www.example.com/b, the client bypasses the reverse proxy and accesses the http://www.test.com/example/b. If a reverse proxy is set, it will be adjusted to http://www.test.com/example/a/b before forwarding the HTTP redirect to the client, that is, appending the redirect path after the original request.

Ubuntu 14.04+apache Reverse proxy settings

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.