Nginx virtual host, reverse proxy instance

Source: Internet
Author: User
Tags sendfile nginx server

First, the main configuration file configuration:

#user nobody;
Worker_processes 4;

Error_log Logs/error.log debug_http;
#error_log Logs/error.log Notice;
#error_log Logs/error.log Info;

#pid Logs/nginx.pid;


Events {
Use Epoll; One way in #epoll是多路复用IO (I/O multiplexing),
Worker_connections 1024; Maximum number of concurrent links #单个后台worker process processes

# Concurrent totals are the product of worker_processes and Worker_connections
# that is max_clients = worker_processes * worker_connections
# in the case of a reverse proxy set, max_clients = worker_processes * WORKER_CONNECTIONS/4 why
# Why the reverse proxy above is divided by 4, should be said to be an empirical value
# Depending on the above conditions, the maximum number of connections that the Nginx server can cope with normally is: 4 * 8000 = 32000
# The setting of the Worker_connections value is related to the physical memory size
# Because of concurrent IO constraints, the value of max_clients must be less than the maximum number of files that the system can open
# while the maximum number of files that the system can open is proportional to the size of the memory, the number of files that can be opened on a 1GB memory machine is about 100,000 or so.
# Let's take a look at the number of file handles that the VPS of 360M memory can open:
# $ Cat/proc/sys/fs/file-max
# Output 34336
# 32000 < 34336, that is, the total number of concurrent connections is less than the total number of file handles that the system can open, which is within the operating system's reach
# Therefore, the value of worker_connections should be set appropriately based on the number of worker_processes processes and the maximum number of files that the system can open
# makes the number of concurrent totals less than the maximum number of files that the operating system can open
# Its essence is configured based on the host's physical CPU and memory
# Of course, the total number of concurrent sums in theory can be somewhat skewed, as the host has other worker processes that consume system resources.
# Ulimit-shn 65535
}
HTTP {
Include Mime.types;#设定mime类型, the type is defined by the Mime.type file

include/usr/local/nginx/conf/conf.d/*.conf; #包含其他文件
Default_type Application/octet-stream;

Sendfile on;

#sendfile instruction Specifies whether Nginx calls the Sendfile function (zero copy mode) to output the file,
#对于普通应用, must be set to ON,
#如果用来进行下载等应用磁盘IO重负载应用, can be set to OFF,
#以平衡磁盘与网络I/O processing speed, reducing the uptime of the system.

#tcp_nopush on;
Keepalive_timeout 120; #连接超时时间

Tcp_nodelay on;

server {
Listen 80;
server_name localhost;
Access_log Logs/access.log;
Error_log Logs/error.log;
CharSet Utf-8;

Location/{
Index index.html index.htm;
root HTML;
}

Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
}
}


Second, the virtual host:

Add vhosts.conf under the CONF.D directory

server {
Listen 172.16.171.101:80;
server_name www.wushank.com;
CharSet Utf-8;
Error_log Logs/wushank/error.log;
Access_log Logs/wushank/access.log;
Location/{
Root/var/www/html/wushank;
Index index.html index.htm;
}
}
server {
Listen 172.16.171.101:80;
server_name www.test.com;
CharSet Utf-8;
Error_log Logs/test/error.log;
Access_log Logs/test/access.log;

Location/{
Root/var/www/html/test;
Index index.html index.htm;
}
}
server {
Listen 10.1.1.100:8000;
server_name localhost;
CharSet Utf-8;
Error_log Logs/wang/error.log;
Access_log Logs/wang/access.log;

Location/{
Root/wang;
Index index.html index.htm;
}
}


Third, reverse proxy configuration:

Upstream F5-test {
Server 172.16.171.100:8080;
Server 172.16.171.110:80;
Server 172.16.171.120:80;
}

server {
Listen 80;
server_name 172.16.171.100 f5.sky.com;

Location ~ \.php$ {
root/var/www/html;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
}

#设置反向代理的全局信息

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 50m;
Client_body_buffer_size 256k;
Proxy_connect_timeout 30;
Proxy_send_timeout 30;
Proxy_read_timeout 60;

Proxy_buffer_size 16k;
Proxy_buffers 4 32k;
Proxy_busy_buffers_size 64k;
Proxy_temp_file_write_size 64k;


#根据URI对不同的目录进行反向代理

location/f5/{
Access_log Logs/f5/access.log;
Error_log Logs/f5/error.log;
Proxy_pass http://f5-test/f5/;
Proxy_redirect default;
}
location/wushank/{
Access_log Logs/wushank/access.log;
Error_log Logs/wushank/error.log;
Proxy_pass http://f5-test/wushank/;
Proxy_redirect default;
}
}


This article is from the "Autumn Fairy tale" blog, please be sure to keep this source http://wushank.blog.51cto.com/3489095/1621543

Nginx virtual host, reverse proxy instance

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.