nginx + thin 运行sinatra(负载均衡)
目标:使用同一机器中的不同端口运行不同项目,使用本机80端口访问,随机跳转到不同项目。
创建简单sinatra项目,并运行起来,比如使用8001,8002,8003三个端口,
ruby -rubygems myapp1.rb -p 8001 ruby -rubygems myapp2.rb -p 8002 ruby -rubygems myapp3.rb -p 8003
例子1 ===============================
upstream thin {
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
}
server {
location / {
proxy_pass http://thin;
}
}
例子2 ===============================
http {
upstream myproject {
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
}
server {
listen 80;
server_name www.domain.com;
location / {
proxy_pass http://myproject;
}
}
}
例子3 ===============================
upstream sitename {
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
}
server {
listen 80;
server_name www.sitename.com;
rewrite ^(/.*) http://sitename.com$1 permanent;
}
server {
listen 80;
server_name sitename.com;
location / {
proxy_pass http://sitename;
}
}