下载
安装(需要gcc环境)
#解压
tar -zxcf ./nginx-1.20.0.tar.gz
#编译
cd nginx-1.20.0/
./configure
#安装
make
make intsall
#运行
whereis nginx
nginx: /usr/local/nginx
cd /usr/local/nginx/sbin
./nginx
#验证出现如下页面说明访问成功
基础命令学习
# 启动
[root@localhost nginx]# sbin/nginx
# -s quit是正常停止。
[root@localhost nginx]# sbin/nginx -s quit
# -s stop是强制停止
[root@localhost nginx]# sbin/nginx -s stop
# 启动状态下重新加载配置文件
[root@localhost nginx]# sbin/nginx -s reload
设置简单的反向代理
- 准备两个test项目demo1 demo2 访问范围 i am demo1 i am demo2用以区分
- 2、启动项目
nohup java -jar demo1.jar --server.port=8081 &
nohup java -jar demo2.jar --server.port=8082 &
修改配置文件
cd /usr/local/nginx/conf/
vim nginx.conf
#修改配置如下 weight 设置权重
upstream demo {
server 127.0.0.1:8081 weight=1;
server 127.0.0.1:8082 weight=2;
}
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
proxy_pass http://demo;
}
- 更新配置
../sbin/nginx -s reload
- 页面访问
补充
location =login {
root html;
index index.html index.htm;
proxy_pass http://demo;
}
会吧请求转发给 http://demo/login
其他匹配规则:详见
其他配置 菜鸟教程