作用:
反向代理,负载均衡,动静分离
Linux安装nginx
- 把nginx上传到linux
scp -P 服务器ssh端口号 /本地路径/文件名 用户名@远程IP:/远程路径/
- 解压nginx-1.xx.x.tar.gz
tar -zxvf nginx-1.xx.x.tar.gz
- 运行配置文件configure 在一个文件夹直接执行不在一个文件夹cd 查看所有文件 ll
./configure
# 2. 编译
make
# 3. 安装
make install
启动nginx以及nginx常用命令
#查找nginx目录
whereis nginx
#启动nginx
cd 上条返回的值/sbin/
./nginx
#停止nginx
./nginx -s stop
#安全退出
./nginx -s quit
#重新加载配置文件
./nginx -s reload
nginx.conf实现负载均衡,反向代理
#负载均衡
upstream test {
#服务器资源
#weight权重
server 127.0.0.1:8080 weight=1;
server 127.0.0.1:8081 weight=1;
}
server {
listen 80;
server_name localhost;
#访问/就进入这里
location / {
root html;
index index.html index.htm;
#反向代理
proxy_pass http://test;
}
#访问静态页面
#注:这个完整访问路径是E://nginx-1.28.1/nginx-1.28.1/html/html/index.html
location /html/ {
root E://nginx-1.28.1/nginx-1.28.1/html;
index index.html;
}
}