nginx Reverse proxy configuration
Nginx Reverse proxy instructions do not need to add additional modules, the default comes with proxy_pass instructions, only need to modify the configuration file can be implemented reverse proxy.
1. Environment
Proxy Server ip:192.168.1.106,
Back-end server 1:192.168.1.112,
Back-end server 2:192.168.1.113.
Access www.jason.com points to the 192.168.1.112 server. Access Www.jason.com/admin points to the 192.168.1.113 server.
2. Modify the configuration file
(1), Proxy server configuration file
User nobody;
Worker_processes 1;
PID Nginx.pid;
Error_log Logs/error.log Notice;
Worker_rlimit_nofile 65535;
Events {
Worker_connections 65535;
Use Epoll;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '
' $status $body _bytes_sent ' $http _referer '
' "$http _user_agent" "$http _x_forwarded_for";
Log_format Download ' $remote _addr-$remote _user [$time _local] "$request" '
' $status $body _bytes_sent ' $http _referer '
' "$http _user_agent" "$http _x_forwarded_for";
Access_log Logs/access.log Main;
Client_max_body_size 20M;
Client_header_buffer_size 4k;
Large_client_header_buffers 4 8k;
Client_header_timeout 10;
Client_body_timeout 10;
Send_timeout 10;
Sendfile on;
Tcp_nopush on;
Tcp_nodelay on;
Keepalive_timeout 60;
gzip on;
Gzip_min_length 1k;
Gzip_http_version 1.1;
Gzip_buffers 4 8k;
Gzip_comp_level 2;
Gzip_types text/plainapplication/x-javascript text/css Application/xml;
Gzip_vary on;
server {
Listen 80;
server_name www.jason.com;
Access_log Logs/access.log Main;
Location/{
Index index.html;
Proxy_pass http://10.18.199.112;
Proxy_redirect off;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for$proxy_add_x_forwarded_for;
Proxy_connect_timeout 90;
Proxy_send_timeout 90;
Proxy_read_timeout 90;
Proxy_buffers 4k;
Proxy_buffer_size 4k;
Proxy_busy_buffers_size 64k;
proxy_temp_file_write_size64k;
}
Location/admin {
Index index.html;
Proxy_pass http://10.18.199.113;
Proxy_redirect off;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_connect_timeout 90;
Proxy_send_timeout 90;
Proxy_read_timeout 90;
Proxy_buffers 4k;
Proxy_buffer_size 4k;
Proxy_busy_buffers_size 64k;
Proxy_temp_file_write_size 64k;
}
Location ~/\.ht {
Deny all;
}
}
}
(2), back-end server 1
User nobody;
Worker_processes 1;
PID Nginx.pid;
Error_log Logs/error.log Notice;
Worker_rlimit_nofile 65535;
Events {
Worker_connections 65535;
Use Epoll;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '
' $status $body_bytes_sent ' $http _referer "'
' "$http _user_agent" "$http _x_forwarded_for";
Log_format Download ' $remote _addr-$remote _user [$time _local] "$request" '
' $status $body _bytes_sent ' $http _referer '
' "$http _user_agent" "$http _x_forwarded_for";
Access_log Logs/access.log Main;
Client_max_body_size 20M;
Client_header_buffer_size 4k;
Large_client_header_buffers 4 8k;
Client_header_timeout 10;
Client_body_timeout 10;
Send_timeout 10;
Sendfile on;
Tcp_nopush on;
Tcp_nodelay on;
Keepalive_timeout 60;
gzip on;
Gzip_min_length 1k;
Gzip_http_version 1.1;
Gzip_buffers 4 8k;
Gzip_comp_level 2;
Gzip_types text/plainapplication/x-javascript text/css Application/xml;
Gzip_vary on;
server {
Listen 80;
server_name www.jason2.com;
Access_log Logs/access.log Main;
Location/{
Index index.html;
Root/usr/local/nginx/html/jason2;
}
Error_page 404/404.html;
Error_page 502 503 504/50x.html;
Location =/50x.html {
root/usr/local/nginx/html;
}
Location =/favicon.ico {
Log_not_found off;
Access_log off;
}
#location/status {
# stub_status on;
# access_log/usr/local/nginx/logs/status.log;
# auth_basic "Nginxstatus";
# auth_basic_user_file/usr/local/nginx/conf/htpasswd;}
Location ~/\.ht {
Deny all;
}
}
}
(3) Proxy server 2:
User nobody;
Worker_processes 1;
PID Nginx.pid;
Error_log Logs/error.log Notice;
Worker_rlimit_nofile 65535;
Events {
Worker_connections 65535;
Use Epoll;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '
' $status $body _bytes_sent ' $http _referer '
' "$http _user_agent" "$http _x_forwarded_for";
Log_format Download ' $remote _addr-$remote _user [$time _local] "$request" '
' $status $body _bytes_sent ' $http _referer '
' "$http _user_agent" "$http _x_forwarded_for";
Access_log Logs/access.log Main;
Client_max_body_size 20M;
Client_header_buffer_size 4k;
Large_client_header_buffers 4 8k;
Client_header_timeout 10;
Client_body_timeout 10;
Send_timeout 10;
Sendfile on;
Tcp_nopush on;
Tcp_nodelay on;
Keepalive_timeout 60;
gzip on;
Gzip_min_length 1k;
Gzip_http_version 1.1;
Gzip_buffers 4 8k;
Gzip_comp_level 2;
Gzip_types text/plainapplication/x-javascript text/css Application/xml;
Gzip_vary on;
server{
Listen 80;
server_name www.jason3.com;
Access_log Logs/access.log Main;
Location/admin {
Index index.html;
root/usr/local/nginx/html;
}
Error_page 404/404.html;
Error_page 502 503 504/50x.html;
Location =/50x.html {
root/usr/local/nginx/html;
}
Location =/favicon.ico {
Log_not_found off;
Access_log off;
}
#location/status {
# stub_status on;
# access_log/usr/local/nginx/logs/status.log;
# auth_basic "Nginxstatus";
# auth_basic_user_file/usr/local/nginx/conf/htpasswd;}
Location ~/\.ht {
Deny all;
}
}
}
3. Test:
Start the proxy server, back-end server 1, and back-end server 2.
Visit www.jason.com The following page appears
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/76/64/wKioL1ZSkZrjd2KAAACkN8gOs_Q241.jpg "title=" 333333333.jpg "alt=" Wkiol1zskzrjd2kaaackn8gos_q241.jpg "/>
Visit Www.jason.com/admin The following page appears
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/76/64/wKioL1ZSkamRYdPXAACcGVLudbs187.jpg "title=" 44444444.jpg "alt=" Wkiol1zskamrydpxaaccgvludbs187.jpg "/>
More Directions agent parameters can be seen in the official detailed explanation http://nginx.org/en/docs/http/ngx_http_proxy_module.html
This article is from "Technical achievement dream!" "Blog, be sure to keep this provenance http://dreamsanqin.blog.51cto.com/845412/1715891
Nginx Reverse proxy configuration