Nginx配置说明

  1 #使用的用户和组,window下不指定 
  2 #user  nobody;
  3 
  4 #指定工作衍生进程数(一般等于CPU总和数或总和数的两倍,例如两个四核CPU,则总和数为8) 
  5 worker_processes  1;
  6 
  7 #指定错误日志文件存放路径,错误日志级别可选项为【debug|info|notice|warn|error|crit】 
  8 #error_log  logs/error.log;
  9 #error_log  logs/error.log  notice;
 10 #error_log  logs/error.log  info;
 11 
 12 #指定pid存放路径 
 13 pid        logs/nginx.pid;
 14 
 15 #工作模式及连接数上限
 16 events {
 17         #使用网络I/O模型,Linux系统推荐使用epoll模型,FreeBSD系统推荐使用kqueue;window下不指定 
 18         #use epoll; 
 19         #允许的连接数 
 20     worker_connections  1024;
 21 }
 22 
 23 #设定http服务器,利用他的反向代理功能提供负载均衡支持 
 24 http {
 25         #设定mime类型 
 26     include       mime.types;
 27     default_type  application/octet-stream;
 28 
 29         #设定日志格式 
 30     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 31     #                  '$status $body_bytes_sent "$http_referer" '
 32     #                  '"$http_user_agent" "$http_x_forwarded_for"';
 33 
 34     #access_log  logs/access.log  main;
 35 
 36     sendfile        on;
 37     #tcp_nopush     on;
 38 
 39     #keepalive_timeout  0;
 40     keepalive_timeout  65;
 41 
 42     #开启gzip模块 
 43     #gzip  on;
 44 
 45     #设定负载均衡的服务器列表
 46     upstream  www.czp.com  {
 47             #根据ip计算将请求分配各那个后端tomcat,可以解决session问题 
 48             ip_hash;
 49 
 50             #同一机器在多网情况下,路由切换,ip可能不同 
 51                 #weigth参数表示权值,权值越高被分配到的几率越大
 52               #这里指定多个源服务器,ip:端口,80端口的话可写可不写 
 53         server   192.168.1.180:8003 weight=1;
 54         server   192.168.1.180:8002;
 55         server   192.168.1.180:8001;
 56     }
 57 
 58     upstream  blog.czp.com  {
 59         server   192.168.1.180:8003;
 60         server   192.168.1.180:8002;
 61         server   192.168.1.180:8001;
 62     }
 63 
 64     #设定虚拟主机 
 65     server
 66     {
 67             listen  80;
 68             server_name  www.czp.com;
 69 
 70             charset UTF-8; 
 71 
 72                         #假如访问 /img/*, /js/*, /css/* 资源,则直接取本地文档,不通过squid 
 73                         #假如这些文档较多,不推荐这种方式,因为通过squid的缓存效果更好 
 74                         #location ~ ^/(img|js|css)/ { 
 75                         # root /data3/Html; 
 76                         # expires 24h; 
 77                         # } 
 78 
 79                         #对 "/" 启用负载均衡 
 80             location / {
 81                      proxy_pass        http://www.zyan.cc;
 82                      proxy_set_header   Host             $host;
 83                      proxy_set_header   X-Real-IP        $remote_addr;
 84                      proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
 85             }
 86     }
 87 
 88     server
 89     {
 90             listen  80;
 91             server_name  blog.czp.com;
 92 
 93             location / {
 94                      proxy_pass        http://blog.zyan.cc;
 95                      proxy_set_header   Host             $host;
 96                      proxy_set_header   X-Real-IP        $remote_addr;
 97                      proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
 98             }
 99     }
100 
101     server {
102         listen       80;
103         server_name  localhost;
104 
105         #charset koi8-r;
106 
107         #access_log  logs/host.access.log  main;
108 
109         location / {
110             root   html;
111             index  index.html index.htm;
112         }
113 
114         #error_page  404              /404.html;
115 
116         # redirect server error pages to the static page /50x.html
117         #
118         error_page   500 502 503 504  /50x.html;
119         location = /50x.html {
120             root   html;
121         }
122 
123         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
124         #
125         #location ~ \.php$ {
126         #    proxy_pass   http://127.0.0.1;
127         #}
128 
129         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
130         #
131         #location ~ \.php$ {
132         #    root           html;
133         #    fastcgi_pass   127.0.0.1:9000;
134         #    fastcgi_index  index.php;
135         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
136         #    include        fastcgi_params;
137         #}
138 
139         # deny access to .htaccess files, if Apache's document root
140         # concurs with nginx's one
141         #
142         #location ~ /\.ht {
143         #    deny  all;
144         #}
145     }
146 
147 
148     # another virtual host using mix of IP-, name-, and port-based configuration
149     #
150     #server {
151     #    listen       8000;
152     #    listen       somename:8080;
153     #    server_name  somename  alias  another.alias;
154 
155     #    location / {
156     #        root   html;
157     #        index  index.html index.htm;
158     #    }
159     #}
160 
161 
162     # HTTPS server
163     #
164     #server {
165     #    listen       443 ssl;
166     #    server_name  localhost;
167 
168     #    ssl_certificate      cert.pem;
169     #    ssl_certificate_key  cert.key;
170 
171     #    ssl_session_cache    shared:SSL:1m;
172     #    ssl_session_timeout  5m;
173 
174     #    ssl_ciphers  HIGH:!aNULL:!MD5;
175     #    ssl_prefer_server_ciphers  on;
176 
177     #    location / {
178     #        root   html;
179     #        index  index.html index.htm;
180     #    }
181     #}
182 
183 }

 

posted @ 2015-09-22 15:37  Czhipu  阅读(259)  评论(0编辑  收藏  举报