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
- At home I can't access Caoliu
- But I have a VPS in America that can access a variety of xxoo websites
- So I sent a request to the VPS, I want to see Caoliu
- 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
- localhost:8080
- localhost:9000
- localhost:8000
I want to use Nginx to make a setup, all use 80 port, eliminate my input port number of distress
- when I visited
xxx
when I agent to localhost:8080
- when I visited
YYY
when I agent to localhost:9000
- Give me a proxy when I visit
zzz
localhost: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