Nginx ("engine X") is a high-performance HTTP and reverse proxy server and an IMAP/POP3/SMTP proxy server. Nginx was developed by the rambler.ru site with the highest access volume in Russia as Igor Sysoev. It has been running on this site for more than two and a half years. Igor willSource codeIssued in the form of a class BSD license. Nginx configuration file details # Running user User nobody Nobody; # Start a process Worker_processes 2; # Global error logs and PID files Error_log logs/error. Log notice; PID logs/nginx. PID; # Working mode and maximum number of connections Events { Use epoll; Worker_connections 1024; } # Set the HTTP server and use its reverse proxy function to provide Load Balancing support HTTP { # Set the MIME type Include CONF/mime. types; Default_type application/octet-stream; # Set the log format Log_format main '$ remote_addr-$ remote_user [$ time_local]' '"$ Request" $ Status $ bytes_sent' '"$ Http_referer" "$ http_user_agent "' '"$ Gzip_ratio "'; Log_format download '$ remote_addr-$ remote_user [$ time_local]' '"$ Request" $ Status $ bytes_sent' '"$ Http_referer" "$ http_user_agent "' '"$ Http_range" "$ sent_http_content_range "'; # Set Request Buffer Client_header_buffer_size 1 K; Large_client_header_buffers 4 4 K;
# Enable the gzip Module Gzip on; Gzip_min_length 1100; Gzip_buffers 4 8 K; Gzip_types text/plain; Output_buffers 1 32 K; Post pone_output 1460; # Setting access log Access_log logs/access. Log main; Client_header_timeout 3 m; Client_body_timeout 3 m; Send_timeout 3 m; Sendfile on; Tcp_nopush on; Tcp_nodelay on; Keepalive_timeout 65; # Set the Server list of Server Load balancer Upstream mysvr { # The weigth parameter indicates the weight. A higher weight indicates a higher probability of being assigned. # Enable port 3128 for squid on the local machine Server 192.168.8.1: 3128 Weight = 5; Server 192.168.8.2: 80 Weight = 1; Server 192.168.8.3: 80 Weight = 6; }
# Set Virtual Hosts Server { Listen 80; SERVER_NAME 192.168.8.1 www.hahaer.com; Charset gb2312; # Set access logs for the current virtual host Access_log logs/www.hahaer.com. Access. Log main; # If you access/img/*,/JS/*,/CSS/* resources, you can directly retrieve the local file without passing squid # This method is not recommended if there are many files, because the Squid cache works better. Location ~ ^/(IMG | JS | CSS )/{ Root/data3/html; Expires 24 h; }
# Enable Server Load balancer "/" Location /{ Proxy_pass http: // mysvr; 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 10 m; Client_body_buffer_size 128 K; Proxy_connect_timeout 90; Proxy_send_timeout 90; Proxy_read_timeout 90; Proxy_buffer_size 4 K; Proxy_buffers 4 32 K; Proxy_busy_buffers_size 64 K; Proxy_temp_file_write_size 64 K; }
# Set the address for viewing nginx status Location/nginxstatus { Stub_status on; Access_log on; Auth_basic "nginxstatus "; Auth_basic_user_file CONF/htpasswd; } } } Note: The content of the conf/htpasswd file can be generated using the htpasswd tool provided by Apache. 3) view nginx running status Enter the http: // 192.168.8.1/nginxstatus/address, and enter the verification account password. The following content is displayed: Active connections: 328 Server accepts handled requests 9309 8982 28890 Reading: 1 writing: 3 waiting: 324 The first line indicates the number of currently active connections. The third number in the third row indicates the total number of requests received from nginx running to the current time. If the number reaches the upper limit, the upper limit must be increased. The fourth line is the nginx queue status.
------------------------------------------------------------------------------
Proxy DNS resolution
Server {
Listen 8080; Location/{proxy_pass http: // $ http_host $ request_uri; access_log off ;}} in the HTTP field, use resolver to specify the DNS server, otherwise, the error "nginx 502 Bad Gateway" will occur. I use the DNS service provided by Google: resolver 8.8.8.8. After the modification, restart the nginx server: nginx-s reload. Finally, modify the browser proxy settings to access www.ip.cn, the IP address is changed.
------------------------------------------------------------------------------
You need to support several websites in nginx. conf add several lines: Server {Listen 80; SERVER_NAME www.3js.com.cn; Location/{proxy_pass http://block.3js.com.cn: 81 ;}} example: Server {Listen 80; SERVER_NAME www.3js.com.cn; Location/{proxy_passhttp: // block.3js.com.cn: 81 ;}} server {Listen 80; SERVER_NAME www1.3js.com.cn; Location/{proxy_passhttp: // block.3js.com.cn: 82 ;}}
Server {Listen 80; SERVER_NAME www2.3js.com.cn; Location/{proxy_passhttp: // block.3js.com.cn: 83 ;}}