1.先下载一个,地址http://nginx.org/
启动命令start nginx 或 nginx.exe,浏览器输入localhost
2.反向代理
location / {
root html;
index index.html index.htm;
}
location / {
proxy_pass https://localhost:8080;
root html;
index index.html index.htm;
}
upstream demo{
server 192.168.2.138:8080;
server 192.168.2.138:8081;
}
修改location为 location / {
proxy_pass https://demo;
root html;
index index.html index.htm;
}
upstream demo{
ip_hash;
server 192.168.2.138:8080;
server 192.168.2.138:8081;
}
4.动静分离
location ~ .*\.(jpg|gif)$ {
root /usr/local/images;
}
location / {
if ($mobile_rewrite = 0) {
proxy_pass http://localhost:8082;
}
proxy_pass http://demo;
root html;
index index.html index.htm;
}
6.站点增加则按照如下配置upstream pc{
ip_hash;
server 192.168.2.138:8080;
server 192.168.2.138:8081;
}
upstream mobile{
ip_hash;
server 192.168.2.138:8082;
server 192.168.2.138:8083;
}
location / {
if ($mobile_rewrite = 0) {
proxy_pass http://mobile;
}
proxy_pass http://pc;
root html;
index index.html index.htm;
}