首先要知道“upstream”配置的位置应该是在 http 模块下,其次应该在server模块外,不可以在server模块下
这是报错时候的配置文件:
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/ main;
location / {
# root html;
# index ;
proxy_pass http://myServer;
}
upstream myServer{
server 127.0.0.1:8081;
server 127.0.0.1:8082;
server 127.0.0.1:8083;
}
}
这是改正之后的:
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/ main;
location / {
# root html;
# index ;
proxy_pass http://myServer;
}
}
#这里把upstream放到server模块外边
upstream myServer{
server 127.0.0.1:8081;
server 127.0.0.1:8082;
server 127.0.0.1:8083;
}
ok!正常启动