Last active
August 29, 2015 14:24
-
-
Save nkcoder/3b61bc73de34b0d424d4 to your computer and use it in GitHub Desktop.
nginx负载均衡的配置
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user nginx; | |
worker_processes auto; | |
error_log /var/log/nginx/error.log warn; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include /etc/nginx/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"'; | |
log_format upstreamlog '$remote_addr - $http_x_forwarded_for - $remote_user [$time_local] ' | |
' $status $body_bytes_sent "$http_referer" "$http_user_agent" ' | |
' "$request" : $request_time sec ' | |
' "$upstream_addr" : $upstream_response_time sec'; | |
access_log /var/log/nginx/access.log main; | |
sendfile on; | |
#tcp_nopush on; | |
keepalive_timeout 65; | |
#gzip on; | |
include /etc/nginx/conf.d/*.conf; | |
# load balance backend servers | |
upstream backend { | |
least_conn; | |
server **.**.**.**:8080; | |
server **.**.**.**:8080; | |
} | |
# shicha app server | |
server { | |
listen 80; | |
server_name api.shichaapp.com; | |
access_log /opt/logs/nginx/timediff.access.log upstreamlog; | |
error_log /opt/logs/nginx/timediff.error.log warn; | |
root html; | |
location / { | |
proxy_pass http://backend; | |
# when server returns http 502, redirect to another server | |
proxy_next_upstream error timeout http_502; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment