Nginx Reverse proxy server load balancer

Source: Internet
Author: User
Tags nginx reverse proxy
Nginx. conf configuration file: usernobodynobody; worker_processes4; error_loglogs/error. logcrit; pidlogs/nginx. pid; worker_rlimit_nofile65

Nginx. conf configuration file:
User nobody;
Worker_processes 4;
Error_log logs/error. log crit;
Pid logs/nginx. pid;
Worker_rlimit_nofile 65535;
Events {
Use epoll;
Worker_connections 65535;
}
Http {
Server_tokens off;
Include mime. types;
Default_type application/octet-stream;
Server_names_hash_bucket_size 128;
 
Sendfile on;
Tcp_nopush on;
Tcp_nodelay on;
Keepalive_timeout 65;
Gzip on;
Gzip_min_length 1 k;
Gzip_buffers 4 16 k;
Gzip_http_version 1.0;
Gzip_comp_level 2;
Gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on;

Upstream mysrv {
Server 192.168.1.1: 80 weight = 1 max_fails = 2 fail_timeout = 30 s;
Server 192.168.1.2: 80 weight = 1 max_fails = 2 fail_timeout = 30 s;
}
Upstream Upload {
Server 192.168.1.3: 80 weight = 1 max_fails = 2 fail_timeout = 30 s;
Server 192.168.1.4: 80 weight = 1 max_fails = 2 fail_timeout = 30 s;
}
Upstream bbs {
Server 192.168.1.5: 80 weight = 1 max_fails = 2 fail_timeout = 30 s;
Server 192.168.1.6: 80 weight = 1 max_fails = 2 fail_timeout = 30 s;
}

Include vhost/*. conf;
}

Aaa_example_com.conf configuration file:
Server {
Listen 80;
Server_name aaa.example.com;
Index. php index.html index.htm index.shtml;

Log_format proxy '$ remote_addr | $ upstream_addr | $ connection | $ upstream_status | $ time_local | $ request |'
'$ Status | $ body_bytes_sent | $ bytes_sent | $ http_referer |'
'$ Http_user_agent | $ upstream_response_time | $ msec | $ request_time ';
Access_log logs/aaa_access.log proxy;

Location /{
Proxy_pass http: // mysrv;
Include proxy. conf;
}

Location/locations /{
Proxy_pass http: // response;
Include proxy. conf;
}
}

Bbs_example_com.conf configuration file:
Server {
Listen 80;
Server_name bbs.example.com * .bbs.example.com;

Log_format proxy '$ remote_addr | $ upstream_addr | $ connection | $ upstream_status | $ time_local | $ request |'
'$ Status | $ body_bytes_sent | $ bytes_sent | $ http_referer |'
'$ Http_user_agent | $ upstream_response_time | $ msec | $ request_time ';
Access_log logs/bbs_access.log proxy;

Location /{
Proxy_pass http: // bbs;
Include proxy. conf;
}

}

Proxy. conf configuration file:
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;
Client_max_body_size 50 m; // maximum number of bytes allowed for client requests per file
Client_body_buffer_size 256 k; // maximum number of bytes requested by the buffer proxy to buffer the client
Proxy_connect_timeout 30; // timeout value for connecting to the backend server
Proxy_send_timeout 30; // timeout value for sending data to the backend server
Proxy_read_timeout 60; // The timeout time for the backend server to respond to the request
Proxy_buffer_size 4 k; // the cache size of the proxy request
Proxy_buffers 4 32 k;
Proxy_busy_buffers_size 64 k; // The proxy_buffers size that can be applied for when the system is busy
Proxy_temp_file_write_size 64 k; // proxy cache temporary file size
Proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; // failover
Proxy_max_temp_file_size 128 m;

The proxy_set_header command is used to add the specified Header information when initiating a request to the backend web server of the reverse proxy. when the backend web server has multiple domain name-based virtual hosts, you must add the Header Host to specify the domain name of the request so that the backend web server can identify the virtual Host that handles the reverse proxy access request.

Related Article

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.