8
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
1
#user nobody;
2 worker_processes 2;
3
4
#error_log logs/error.log;
5
#error_log logs/error.log notice;
6
#error_log logs/error.log info;
7
8
#pid logs/nginx.pid;
9
10
11 events {
12 worker_connections 1024;
13 }
14
15
16 http {
17
18
#设定mime类型,类型由mime.type文件定义
19 include mime.types;
20 default_type application
/octet-stream
;
21
22
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
23
# '$status $body_bytes_sent "$http_referer" '
24
# '"$http_user_agent" "$http_x_forwarded_for"';
25
26
#access_log logs/access.log main;
27
28 sendfile on;
29
#tcp_nopush on;
30
31
#keepalive_timeout 0;
32 keepalive_timeout 65;
33
34
#gzip on;
35
36
#后端服务器
37
#使用权重,设置负载均衡参数
38 upstream backend {
39
#server 192.168.0.106:8080 weight=2 max_fails=3;
40
#server 192.168.0.105:8080 weight=1;
41 server 192.168.0.106:8080;
42 server 192.168.0.105:8080;
43 }
44
45
#配置虚拟主机
46 server {
47
48
##监听端口
49 listen 80;
50
51
52
#虚拟主机的名字
53
#使用localhost
54
#server_name localhost;
55
#nginx服务器ip
56
#server_name 192.168.0.106;
57
##使用域名来绑定
58 server_name www.ceit.com;
59
60
#charset koi8-r;
61
62
#access_log logs/host.access.log main;
63
64
#默认请求(拦截/)
65
#location / {
66
# #定义首页索引文件的名称
67
# #index index.php index.html index.htm;
68
#}
69
70 location / {
71 index index.html index.htm;
72
#后面没有配置正斜杠,即绝对根路径。如果配了,
73
#nginx不会把location中匹配的路径部分代理走
74
#通过后端服务器代理,实现负载均衡
75 proxy_pass http:
//backend
;
76
77
#代理部分的参数设置
78 proxy_redirect off;
79 proxy_set_header Host $host;
80 proxy_set_header X-Real-IP $remote_addr;
81 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
82 client_max_body_size 10m;
83 client_body_buffer_size 128k;
84 proxy_connect_timeout 15;
85 proxy_send_timeout 15;
86 proxy_read_timeout 15;
87 proxy_buffer_size 8k;
88 proxy_buffers 4 64k;
89 proxy_busy_buffers_size 128k;
90 proxy_temp_file_write_size 128k;
91 }
92
93
#static file
94 location ~* ^.+\.(ico|gif|jpg|jpeg|png|html|htm)$ {
95 root
/static
;
96 proxy_pass http:
//backend
;
97 access_log off;
98 expires 30d;
99 }
100
101
#static file
102 location ~* ^.+\.(css|js|txt|xml|swf|wav)$ {
103 root
/static
;
104 proxy_pass http:
//backend
;
105 access_log off;
106 expires 24h;
107 }
108 }
109 }
|
user nginx nginx;
worker_processes 2; #相当于cpu个数
error_log logs/nginx_error.log ; #错误日志 crit 日志格式
pid /usr/local/nginx/nginx.pid; #主进程PID保存文件
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535; #文件描述符数量
events
{
use epoll; #网络I/O模型,建议linux使用epoll,FreeBSD使用kqueue
worker_connections 65535; #最大允许连接数
}
http #全局设置
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on; #tcp延迟
keepalive_timeout 60; #保持连接时间
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k; #fastcgi设置
gzip on; #开启gzip压缩,大大加速网页传输速度,节省了带宽,以下都是gzip的设置
gzip_proxied any;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 2;
gzip_types text/html text/text text/plain application/x-javascript text/css application/xml application/x-httpd-php image/jpeg image/png image/gif ;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
server #设置网站的基本信息,当有多个server时,就能实现虚拟主机的功能了,我的有4个,因此就有四个虚拟主机
{
listen 80; #监听端口
server_name www.it163.org; #绑定域名
index index.html index.htm index.php; #默认首页
root html; #网站根目录
error_page 404 /404.html; #404错误页面地址
location = /404.html {
root html; #404错误页面地址位置
}
if ( $host = it163.org ) {
rewrite ^ http:// www.it163.org $request_uri redirect;
} #301重定向redirect 表示返回的状态码是301
#limit_conn crawler 20;
location ~ .*\.(php|php5)?$ #解析php文件
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d; #图片格式缓存30天
}
location ~ .*\.(js|css)?$
{
expires 1h; #js/css缓存1小时
}
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for'; #访问日志文件格式
access_log logs/access.log access;
}
server #第二个虚拟主机
{
listen 80;
server_name www.apkpk.com apkpk.com;
index index.html index.htm index.php;
root /web/www.apkpk.com;
error_page 404 /404.html;
location = /404.html {
root /web/www.apkpk.com;
}
if ( $host = apkpk.com ) {
rewrite ^ http://www.apkpk.com$request_uri redirect;
}
#limit_conn crawler 20;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log logs/apkpk.access.log;
}
server #第三个虚拟主机
{
listen 80;
server_name www.tu8cn.com tu8cn.com;
index index.html index.htm index.php;
root /web/www.tu8cn.com;
error_page 404 /404.html;
location = /404.html {
root /web/www.tu8cn.com;
}
if ( $host = tu8cn.com ) {
rewrite ^ http://www.tu8cn.com$request_uri redirect;
}
#limit_conn crawler 20;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log logs/tu8cn.access.log;
}
server #第四个虚拟主机
{
listen 80;
server_name www www.it163.org it163.org
index index.html index.htm index.php;
root /web/www.ecshop.com;
error_page 404 /404.html;
location = /404.html {
root /web/www.tu8cn.com;
}
if ( $host = ecshop.com ) {
rewrite ^ http://www.it163.org $request_uri redirect;
}
#limit_conn crawler 20;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log logs/ecshop.access.log;
}
server #这个不是显示虚拟主机,显示服务器负载情况
{
listen 80;
server_name www.it138.org;
location / {
stub_status on;
access_log off;
}
}
}