Load Nginx in Ubuntu for high-performance WEB Server 2-log Optimization

Source: Internet
Author: User
Next article (http://www.linuxidc.com/Linux/2012-05/61327.htm), the website architecture adopts nginx1 + 2 architecture, two backend apache2web servers. Learn more: Load Nginx in Ubuntu for high-performance WEB servers: http://www.linuxidc.com/linux/2012-05/61327.htmubuntunginxfor load-carrying high-performance WEB Servers

Next article (http://www.linuxidc.com/Linux/2012-05/61327.htm), the website architecture adopts nginx 1 + 2 architecture, two backend apache2web servers.

Related reading:

Ubuntu Nginx load Implementation of High Performance WEB Server http://www.linuxidc.com/Linux/2012-05/61327.htm
Nginx under Ubuntu load Implementation of High Performance WEB Server 2-log optimization http://www.linuxidc.com/Linux/2012-05/61328.htm
Ubuntu Nginx load Implementation of High Performance WEB Server 3-PHP website deployment and time synchronization http://www.linuxidc.com/Linux/2012-05/61329.htm
Ubuntu Nginx load to achieve high performance WEB server 4---RSYNC to achieve site synchronization http://www.linuxidc.com/Linux/2012-05/61330.htm
Ubuntu Nginx load Implementation of High Performance WEB Server 5 --- MySQL master synchronization http://www.linuxidc.com/Linux/2012-06/61687.htm

1. Environment

Front-end nginx: Internet 192.168.80.8 Intranet 192.168.1.8 ubuntu10.10 X86 + nginx 1.0.14

Backend web1: Intranet 192.168.1.9 ubuntu10.10 X86 + apache 2.2.16 + mysql 5.1.61 + PHP 5.3.3

Backend web2: Intranet 192.168.1.10 ubuntu10.10 X86 + apache 2.2.16 + mysql 5.1.61 + PHP 5.3.3

Notice: You need to make the same settings on web1 and web2, or do a good job of synchronization.

2. First, check the front-end nginx settings/etc/nginx/conf. d/default. conf.

Upstream loadbalance {

Server 192.168.1.9 weight = 10 max_fails = 3 fail_timeout = 30 s; # Reverse proxy to Web server 1

Server 192.168.1.10 weight = 10 max_fails = 3 fail_timeout = 30 s; # Reverse proxy to Web server 2

Server 192.168.1.11 backup;

Server 192.168.1.12 down;

# Ip_hash;

}

Server

{

Listen 192.168.80.8: 80; # Listen on the external interface

Server_name 192.168.80.8; # The server name, also can www.xxx.com

Location /{

Proxy_pass http: // loadbalance; # Load balance the URL location "/" to the upstream loadbalance

Proxy_set_header Host $ host;

Proxy_set_header X-Real-IP $ remote_addr;

Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for; # Get the real client ip address

}

Log_format 192.168.80.8 '$ remote_addr-$ remote_user [$ time_local] $ request'

'"$ Status" $ body_bytes_sent "$ http_referer "'

'"$ Http_user_agent" "$ http_x_forwarded_for "';

Access_log/var/log/nginx/access. log 192.168.80.8; # access log format

Location/nginx_status {# nginx status monitor

Stub_status on;

Access_log off;

Allow 10.10.10.3;

Deny all ;}# only allow 10.10.10.3 access

}

The following code indicates that the "proxy_set_header" command is used to send a real IP address to the backend apache2.

Proxy_set_header Host $ host; # Add the specified header information when initiating a request to the backend server

Proxy_set_header X-Real-IP $ remote_addr; # send a Real IP address to the backend server

Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for; # allows the backend to directly obtain the real IP address through the variable

If you do not have these statements, you can see that the apache access logs are all access records of 127.0.0.1.

Root @ ubuntu2 :~ # Less/var/log/apache2/access. log

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.