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;
}