- #user nobody;
- worker_processes 1;
- error_log logs/error.log;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- sendfile on;
- keepalive_timeout 65;
- #gzip on;
- upstream www.docyeah.com {
- server 192.168.1.11:8080;
- server 192.168.1.101:8080;
- }
- server {
- listen 80;
- server_name www.docyeah.com;
- charset utf-8;
- location / {
- root html;
- index index.html index.htm;
- proxy_pass http://www.docyeah.com;
- proxy_set_header X-Real-IP $remote_addr;
- client_max_body_size 100m;
- }
- location ~ ^/(WEB-INF)/ {
- deny all;
- }
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
- }
-
将www.docyeah.com替换成你的域名
192.168.1.11和192.168.1.101替换成你服务器的IP
OK,已经完成。启动nginx即可。
nginx在配置upstream时,有两个参数:
ip_hash(同一IP一直使用同一台server服务)
weight(server的使用权重,数值越大,nginx分发的请求越多)