NGINX的安装
- 关闭防火墙
- 安装JAVA和TOMCAT, 并修改环境变量
- 安装软件
yum install -y gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
- 在
/usr/local
下解压nginx安装包 - 使用目录下
configure
命令进行编译,&&
表示连续执行三个命令
./configure && make && make install
- 在/usr/local目录下生成新的nginx目录, 即编译后目录
- 在sbin目录下运行nginx程序, 启动nginx服务
- 在浏览器中输入主机IP地址即可访问nginx
- 关闭NGINX, 分别表示停止服务,退出,重新加载reload
./nginx -s stop/quit/reload
NGINX简介
- 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器
- 因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名
- 一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行
- 特点: 占有内存少,并发能力强
NGINX的使用
- 修改配置文件conf/nginx.conf,可以通过修改server_name的localhost为IP地址或域名,同时分别修改linux的和windows本地的host文件(
C:\Windows\System32\drivers\etc
)映射IP地址和域名 - 可以在html目录下上传图片,以图片名为网址访问
- 通过一台虚拟机上的nginx可以管理两台虚拟机的tomcat,通过配置nginx.conf实现
upstream tomcat{
server 192.168.230.159:8080;
server 192.168.230.160:8080;
}
location / {
#root html;
proxy_pass http://tomcat;
index index.html index.htm;
}
登录nginx会在两个tomcat之间循环调用