Front Nginx rear Apache+node reverse Proxy

Source: Internet
Author: User
Tags vps

The first is to use Apache, because the use of Mac installation mod_proxy and complex configuration to die, the key is also failed ... (Failure reason), the lake rumors nginx to do reverse proxy configuration is simple, tried a bit nginx, sure enough

Working principle

What are the new small partners who may ask what is the reverse proxy? Why use a reverse proxy instead of an urgent port number?

Forward Proxy

Understand the reverse proxy before you understand the forward proxy, the forward proxy is our usual understanding of the agent, for example

    1. At home I can't access Caoliu
    2. But I have a VPS in America that can access a variety of xxoo websites
    3. So I sent a request to the VPS, I want to see Caoliu
    4. VPS Get Caoliu content and then return it to me

VPS is the agent, this process is the forward proxy

A forward proxy is a server that is located between the client and the originating server, in order to obtain content from the original server, the client sends a request to the agent and specifies the target (the original server), and the agent forwards the request to the original server and returns the obtained content to the client. The client must make some special settings to use the forward proxy

Reverse Proxy

For example, Caoliu's domain name often changes, and will provide multiple domain names, a domain name has been wall dropped, can use other, but access to each domain name returned content is the same, and the page is not redirected

In fact, when we visited xx.xxx.cl, the Web server of the domain name did not return the content directly to us, but instead sent the request to Caoliu's real host, and then gave us the result of the request.

The reverse proxy is like the original server for the client, and the client does not need to make any special settings. The client sends a normal request to the content in the reverse proxy's namespace, and then the reverse proxy determines where (the originating server) forwards the request and returns the obtained content to the client, as if the content were its own.

Difference & Use

Actually understand the principle of the difference between the two is obvious, you can simply distinguish the forward proxy and reverse proxy

The reverse proxy is transparent to the visitor (you think xx.xxx.cl is the server address of the Caoliu, actually not, you can't see), the proxy access needs special settings (otherwise how to see YouTube)

A typical use of a forward proxy is to provide access to the Internet for LAN clients within the firewall. Forward proxies can also use buffering features to reduce network usage. A typical use of a reverse proxy is to provide the server behind the firewall to Internet users for access. The reverse proxy can also provide load balancing for multiple servers in the backend, or provide buffering services for servers with slower back-end.

See what I'm going to do with this?

So I have three websites

    1. localhost:8080
    2. localhost:9000
    3. localhost:8000

I want to use Nginx to make a setup, all use 80 port, eliminate my input port number of distress

  1. when I visited  xxx when I agent to localhost:8080
  2. when I visited  YYY when I agent to localhost:9000
  3. Give me a proxy when I visit zzzlocalhost:8000
Apache Configure each site to modify httpd.conf

The configuration file for Mac under Apache

/etc/ apache2/httpd.conf   

#

include  /private/  etc/apache2/ extra/httpd-vhosts.conf  

listen for the corresponding port (do not listen for 80, Give Nginx a moment)

Listen 8000Listen 8080Listen 9000
Modify Httpd-vhosts.conf

The configuration file for the virtual host is

/etc/apache2/extra/httpd-vhosts.conf

Add a virtual host node, like this to three

 <virtualhost *:8080>DocumentRoot "/path"ServerNameXxx<directory "/path" >OptionsIndexes FollowSymLinksallowoverride  AllOrderDeny,allow AllowFrom All</Directory></VirtualHost>
Modify the Hosts file

If the server is local, we also need to configure the domain name to Localhost,mac under the hosts configuration file in the

/etc/hosts

Simply add one of our three hosts

localhost xxx yyy zzz
modifying Nginx configuration Files

The Nginx configuration file installed under Mac using homebrew

/usr/local/etc/nginx/nginx.conf

Then add the server node

Server{Listen  the;server_namexxx Location/{Proxy_pass http://127.0.0.1:8080;Proxy_set_headerHost$host;}}

proxy_set_header Host $host xxx that can keep the URL always configured

This restart Nginx, Apache after the browser input xxx/ can be directly agent to http://127.0.0.1:8080 , no port number


Source: >  

From for notes (Wiz)

Pre-nginx apache+node reverse proxy

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.