下載下傳
安裝(需要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
#驗證出現如下頁面說明通路成功
基礎指令學習
# 啟動
[[email protected] nginx]# sbin/nginx
# -s quit是正常停止。
[[email protected] nginx]# sbin/nginx -s quit
# -s stop是強制停止
[[email protected] nginx]# sbin/nginx -s stop
# 啟動狀态下重新加載配置檔案
[[email protected] 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
其他比對規則:詳見
其他配置 菜鳥教程