Nginx
1、install
Mac
brew install nginx
2、啟動
指定配置文件啟動
nginx -c ~/develop/install/nginx/nginx.conf
檢查配置文件是否有錯
nginx -t
重啟
nginx -s reload
停止
nginx -s stop
3、server 虛擬主機
http節(jié)點下可以配置多個server,配置如下:
server {
listen 80;
server_name localhost;
location / {
root html;
}
}
-
通過端口區(qū)分
server_name一致時,通過監(jiān)聽不同的端口區(qū)分虛擬主機
-
通過域名訪問
監(jiān)聽相同端口時,通過http header中的Host,查找匹配server_name的虛擬主機
4、反向代理
啟動兩個tomcat,端口號分別為8888、9999。
增加如下配置:
upstream nginx {
server localhost:8888;
server localhost:9999;
}
修改如下配置
location / {
# root /Users/zhang/develop/install/nginx/html1;
proxy http://nginx
}