Nginx Configuration File explanation (reference)

Source: Internet
Author: User
Tags imap
Nginx (enginex) is a high-performance HTTP and reverse proxy server and an IMAPPOP3SMTP proxy server. Nginx was developed by the Rambler.ru site with the highest access volume in Russia as IgorSysoev. It has been running on this site for more than two and a half years. Igor publishes source code in the form of a class BSD license. Nginx

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 publishes source code in the form of a class BSD license. Nginx

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 publishes source code in the form of a class BSD license.

NginxConfigurationFileDetails

# Running user

User nobody;

# Start a process

Worker_processes 2;

# Global error log and PIDFile

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, directly obtain the localFile, Does not pass squid

# IfFileThis method is not recommended because the squid cache has a better effect.

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: conf/htpasswdFileThe content 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 addition, you also need to use resolver to specify the DNS server in the http field, otherwise the "nginx 502 bad gateway" error will occur. I use the DNS service provided by Google:

Resolver 8.8.8.8;

After modification, restart the nginx Server:

Nginx-s reload

Finally, modify the browser proxy settings and access www.ip.cn to see that the IP address has changed.

------------------------------------------------------------------------------

Add several lines in nginx. conf to support several websites:

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 ;}}

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.