要用nginx 1.4.4来做负载均衡,以前完全没接触过,出了很多问题,一点点记录下来。
0、不能使用记事本编辑nginx.conf,
conf文件被记事本编辑过,保存成了含BOM头的文件
使用其他编辑器将文件另存为UTF-8不含Bom头的格式
注:记事本编辑UTF-8都会加BOM头
链接为http://www.bubuko.com/infodetail-1001922.html
1、root /html;和root html;前一个指盘符下的路径,后一个是nginx根目录下的路径,例如 E:/html/index.html和E:/nginx-1.4.4/html/index.html
2、多次执行了start nginx,在进程中出现很多nginx的进程,后面修改nginx.conf会失效
3、proxy_set_header Host $host:port;和listen port 两个端口一致
4、在upstream中只能设置ip和port,但是访问的时候要使用项目地址/aaa,
有几种方法:1、http://server_name/aaa 手动加项目地址
2、将aaa改成ROOT
3、使用proxy_pass http://backend/aaa/;但是项目中的其他地址访问会有问题
4、proxy_pass http://backend; rewrite ^/$ /aaa last;这样会在地址中自动加上/aaa
假如有更好的方法请留言。