您的位置:首页 > 运维架构 > Nginx

nginx 配置文件详解

2014-11-21 16:10 211 查看
原文地址:点击打开链接

1

user nobody nobody;

2

#启动进程

3

worker_processes 5;

4

#全局错误日志及PID文件

5

error_log logs/error.log notice;

6

pid logs/nginx.pid;

7

#工作模式及连接数上限

8

events {

9

#工作模式有:select(标准模式),poll(标准模式),kqueue(高效模式,适用FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 and MacOS X),

10

#epoll(高效模式,本例用的。适用Linux 2.6+,SuSE 8.2,),

#/dev/poll(高效模式,适用Solaris 7 11/99+, HP/UX 11.22+ (eventport), IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+)

11

use epoll;

12

worker_connections 1024;

13

}

14

#设定http服务器,利用它的反向代理功能提供负载均衡支持

15

http {

16

#设定mime类型

17

include conf/mime.types;

18

default_type application/octet-stream;

19

#设定日志格式

20

log_format main '$remote_addr - $remote_user [$time_local] '

21

'"$request" $status $bytes_sent '

22

'"$http_referer" "$http_user_agent" '

23

'"$gzip_ratio"';

24


25

log_format download '$remote_addr - $remote_user [$time_local] ' '"$request" $status $bytes_sent ' '"$http_referer" "$http_user_agent" ' '"$http_range" "$sent_http_content_range"';

26

#设定请求缓冲

27

client_header_buffer_size 10k;

28

large_client_header_buffers 4 4k;

29


30

#开启gzip模块,要求安装gzip 在运行./config时要指定

31

gzip on;

32

gzip_min_length 1100;

33

gzip_buffers 4 8k;

34

gzip_types text/plain;

35

output_buffers 1 32k;

36

postpone_output 1460;

37

#设定访问日志

38

access_log logs/access.log main;

39

client_header_timeout 3m;

40

client_body_timeout 3m;

41

send_timeout 3m;

42

sendfile on;

43

tcp_nopush on;

44

tcp_nodelay on;

45

keepalive_timeout 65;

46


47

#设定负载均衡的服务器列表

48

upstream backserver {

49

#weigth参数表示权值,权值越高被分配到的几率越大

50

#本例是指在同一台服务器,多台服务器改变ip即可

51

server 127.0.0.1:8081 weight=5;

52

server 127.0.0.1:8082;

53

server 127.0.0.1:8083;

54

}

#Deny access to any host other than (www).4535.com

server {

server_name _; #default

return 404;

}

55

#设定虚拟主机,默认为监听80端口,改成其他端口会出现问题

56

server {

57

listen 80;

58

server_name test.com www.test.com;

59

charset utf8;

60

#设定本虚拟主机的访问日志

61

access_log logs/test.com.log main;

62

#如果访问 /images/*, /js/*, /css/* 资源,则直接取本地文件,不用转发。但如果文件较多效果不是太好。

63

location ~ ^/(images|js|css)/ {

64

root /usr/local/testweb;

65

expires 30m;

66

}

67

#对 "/" 启用负载均衡

68

location / {

69

proxy_pass http://backserver;
70

proxy_redirect off;

71

proxy_set_header Host $host;

72

proxy_set_header X-Real-IP $remote_addr;

73

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

74

client_max_body_size 10m;

75

client_body_buffer_size 128k;

76

proxy_connect_timeout 90;

77

proxy_send_timeout 90;

78

proxy_read_timeout 90;

79

proxy_buffer_size 4k;

80

proxy_buffers 4 32k;

81

proxy_busy_buffers_size 64k;

82

proxy_temp_file_write_size 64k;}

83

#设定查看Nginx状态的地址,在运行./config 要指定,默认是不安装的。

84

location /NginxStatus {

85

stub_status on;

86

access_log on;

87

auth_basic "NginxStatus";

88

#是否要通过用户名和密码访问,测试时可以不加上。conf/htpasswd 文件的内容用 apache 提供的 htpasswd 工具来产生即可#auth_basic_user_file conf/htpasswd;

89

}

90

}

91
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: