|
1
2
3
4
5
|
server_name qunying.dianping.com;
location / {
proxy_pass test.qunying.liu.dianping.com; //反向代理站。
index index.html index.htm;
}
|
gzip模块需要 zlib 库
rewrite模块需要 pcre 库
ssl 功能需要openssl库
#运行用户(worker进程属主) user nobody; #启动进程,设置成和cpu的数量相等
过多的worker数,只会导致进程相互竞争cpu资源,从而带来不必要的上下文切换
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
worker_processes 4;
#全局错误日志及PID文件
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
#工作模式及连接数上限
events {
#epoll是多路复用IO(I/O Multiplexing)中的一种方式,
#仅用于linux2.6以上内核,可以大大提高nginx的性能
use epoll;
#单个后台worker process进程的最大并发链接数
worker_connections 1024;
# 并发总数是 worker_processes 和 worker_connections 的乘积
# 即 max_clients = worker_processes * worker_connections
# worker_connections 值的设置跟物理内存大小有关
# 因为并发受IO约束,max_clients的值须小于系统可以打开的最大文件数
# 系统可以打开的最大文件数和内存大小成正比
# $ cat /proc/sys/fs/file-max
# 并发连接总数小于系统可以打开的文件句柄总数,这样就在操作系统可以承受的范围之内
# worker_connections 的值需根据 worker_processes 进程数目和系统可以打开的最大文件总数进行适当地进行设置
# 根据主机的物理可用CPU和可用内存进行配置
}
http {
#设定mime类型,类型由mime.type文件定义
include mime.types;
default_type application/octet-stream;
#设定日志格式
log_format main '$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 main;
#sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,
#对于普通应用,必须设为 on,
#如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,以平衡磁盘与网络I/O处理速度,降低系统的uptime.
sendfile on;
#tcp_nopush on;
#连接超时时间
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
#开启gzip压缩
gzip on;
gzip_disable "MSIE [1-6].";
#设定请求缓冲
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;
#设定虚拟主机配置
server {
#侦听80端口
listen 80;
#定义使用 访问
server_name ;
#定义服务器的默认网站根目录位置
root html;
#设定本虚拟主机的访问日志
access_log logs/nginx.access.log main;
#默认请求
location / {
#定义首页索引文件的名称
index index.php index.html index.htm;
}
# 定义错误提示页面
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
#静态文件,nginx自己处理
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
#过期30天,静态文件不怎么更新,过期可以设大一点,
#如果频繁更新,则可以设置得小一点。
expires 30d;
}
#PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#禁止访问 .htxxx 文件
location ~ /.ht {
deny all;
}
}
}
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
user nobody nobody;
worker_processes 4;
worker_rlimit_nofile 51200;
error_log logs/error.log notice;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 51200;
}
http {
server_tokens off;
include mime.types;
include proxy.conf;
default_type application/octet-stream;
charset utf-8;
client_body_temp_path /usr/local/nginx/tmpdir/client_body_temp 1 2;
proxy_temp_path /usr/local/nginx/tmpdir/proxy_temp 1 2;
fastcgi_temp_path /usr/local/nginx/tmpdir/fastcgi_temp 1 2;
uwsgi_temp_path /usr/local/nginx/tmpdir/uwsgi_temp 1 2;
scgi_temp_path /usr/local/nginx/tmpdir/scgi_temp 1 2;
ignore_invalid_headers on;
server_names_hash_max_size 256;
server_names_hash_bucket_size 64;
client_header_buffer_size 8k;
large_client_header_buffers 4 32k;
connection_pool_size 256;
request_pool_size 64k;
output_buffers 2 128k;
postpone_output 1460;
client_header_timeout 1m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;
tcp_nodelay on;
tcp_nopush off;
reset_timedout_connection on;
keepalive_timeout 20 5;
keepalive_requests 100;
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_proxied any;
gzip_min_length 1024;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_proxied expired no-cache no-store private auth no_last_modified no_etag;
gzip_types text/plain application/x-javascript text/css application/xml application/json;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
include nginx_app.conf; #与应用有关的server配置
include nginx_status.conf; #单机nginx访问统计配置
|
在server里加上如下三行即可。
autoindex on;
autoindex_localtime on;
autoindex_exact_size off;
在location段内添加:
auth_basic "phoenix slb admin ";
auth_basic_user_file /data/appdatas/phoenix-slb-passwd;
本文内容选自51CTO学院讲师马哥博客,更多Linux集群资料点击:http://edu.51cto.com/course/course_id-368.html
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30605389/viewspace-2103274/ ,如需转载,请注明出处,否则将追究法律责任。