Nginx forward proxy
server {
listen 8090;
server_name www.gps.com;
location / {
resolver 218.85.157.99 218.85.152.99;
resolver_timeout 30s;
proxy_pass http://$host$request_uri;
}
access_log /data/httplogs/proxy-$host-aceess.log;
}
Test:
http://www.gps.com:8090
Resolver command
syntax: resolver address… [valid=time];
Default value:
—Configuration section: http, server, location
Configure the DNS server IP address. You can specify more than one and request them in polling mode.
Nginx will cache the results of the analysis. By default, the cache time is the value of the TTL field in the name resolution response, which can be changed through the valid parameter.resolver_timeout command
Syntax: resolver_timeout time;
default value: resolver_timeout 30s;
configuration section: http, server, location
resolution timeout time.
Nginx reverse proxy
1. Ordinary polling
server {
listen 80;
server_name www.123.com;
location / {
proxy_pass http://127.0.0.1:8080;
index index.html index.htm index.jsp;
}
}
We listen on port 80, and the access domain name is www.123.com. If the port number is not added, port 80 is the default, so when accessing the domain name, it will jump to the path 127.0.0.1:8080.
nginx load balancing
upstream OrdinaryPolling {
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://OrdinaryPolling;
index index.html index.htm index.jsp;
}
}
2. Based on proportional weighted polling
upstream OrdinaryPolling {
server 127.0.0.1:8080 weight=5;
server 127.0.0.1:8081 weight=2;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://OrdinaryPolling;
index index.html index.htm index.jsp;
}
}
Route load based on IP
upstream OrdinaryPolling {
ip_hash;
server 127.0.0.1:8080 weight=5;
server 127.0.0.1:8081 weight=2;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://OrdinaryPolling;
index index.html index.htm index.jsp;
}
}
3. Load distribution based on server response time
upstream OrdinaryPolling {
server 127.0.0.1:8080 weight=5;
server 127.0.0.1:8081 weight=2;
fair;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://OrdinaryPolling;
index index.html index.htm index.jsp;
}
}
4. Realize load balancing for different domain names
upstream wordbackend {
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}
upstream pptbackend {
server 127.0.0.1:8082;
server 127.0.0.1:8083;
}
server {
listen 80;
server_name localhost;
location /word/ {
proxy_pass http://wordbackend;
index index.html index.htm index.jsp;
}
location /ppt/ {
proxy_pass http://pptbackend;
index index.html index.htm index.jsp;
}
}
Static resource server
server {
listen 8300;
server_name localhost;
location / {
root /home/testStatic;
access_log on;
autoindex on;
}
}
server_name: domain name
listen: port
root: the path of the static page