ngx_http_upstream_module 模块是用来定义被proxy_pass,fastcgi_pass,uwsgi_pass,scgi_pass, and memcached_pass指令引用的服务器组。
upstream backend {
server backend1.example.com weight=5;
server backend2.example.com:8080;
server unix:/tmp/backend3;
server backup1.example.com:8080 backup;
server backup2.example.com:8080 backup;
}
server{
listen 80;
listen 443;
server_name www.baidu.com;
if ($scheme = "http"){
return 301 https://$server_name$request_uri;
}
ssl on;
ssl_certificate /path/to/https/xx.crt;
ssl_certificate_key /path/to/key/xx.key;
location / {
#proxy_pass http://127.0.0.1:9002; 采用http通讯
include uwsgi_params; 这里采用 proxy_pass
uwsgi_pass 127.0.0.1:9002; uwsig配置socket
# 这里也可以配置upstream 负载均衡
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ ^/favicon\.ico$ {
root /path/to/ico/;
}
location ~ ^/c2c_static/ {
root /path/to/static/;
}
location ~ ^/media/ {
root /path/to/media/;
}
}
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /xxx/xxx
# Django's wsgi file
module = xxx.wsgi
# the virtualenv (full path)
# home = /path/to/virtualenv
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 4
#socket = :9001 这里需要跟nginx 配置一样
http = :9001 # 这里需要跟nginx 配置一样
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
# buffer-size = 123 设置缓存区大小
vacuum = true
#daemonize = /xxx/xx/xxx.log
log-maxsize = 50000000
# log-maxsize :以固定的文件大小(单位KB),切割日志文件。 例如: 就是50M一个日志文件。
pidfile = /pidfiles/uwsgi/uwsgi.pid
# 指定pid文件的位置,记录主进程的pid号。
disable-logging = true
# 自动重启
py-autoreload = 1
# 那么浏览器请求uwsgi的方式为http协议,而不是socket方式。所以就导致uwsgi的log文件中打出上面的错误信息。
# 那么修改里面内容把socket=:8000替换成http=:8000。 但不能都用
# uwsgi -d 后台运行
# uwsgi --reload /pidfiles/uwsgi/uwsgi.pid