1、Nginx是什么
定义:
Nginx (“engine x”) 是一个高性能的HTTP和反向代理服务器,特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、京东、新浪、网易、腾讯、淘宝等。
2、nginx与tomcat之间的关系:
除了tomcat以外,apache,nginx,jboss,jetty等都是http服务器。
但是nginx和apache只支持静态页面和CGI协议的动态语言,比如perl、php等,但是nginx不支持java。
Java程序只能通过与tomcat配合完成。
nginx与tomcat 配合,为tomcat集群提供反向代理服务、负载均衡等服务
3、Nginx三大功能
(1)什么是反向代理?
先看什么是正向代理
再看什么是反向代理
(2)负再均衡
(3)静动分离
4、安装nginx
(1)Linux环境下载安装包,执行命令:
[root@hadoop105 nginx]# wget http://nginx.org/download/nginx-1.11.5.tar.gz
//查看文件
[root@hadoop105 nginx]# ll
total 936
-rw-r--r--. 1 root root 956517 Oct 11 2016 nginx-1.11.5.tar.gz
(2)解压安装包
//解压安装包
[root@hadoop105 nginx]# tar -zxvf nginx-1.11.5.tar.gz
//执行一下依赖包
yum install gcc-c++
yum install pcre
yum install pcre-devel
yum install zlib
yum install zlib-devel
yum install openssl
yum install openssl-devel
//进入解压缩目录,执行
[root@hadoop105 nginx-1.11.5]# ./configure
//执行
[root@hadoop105 nginx-1.11.5]# make
[root@hadoop105 nginx-1.11.5]# make install
//查看版本
[root@hadoop105 nginx-1.11.5]# nginx -v
nginx version: nginx/1.11.5
//查看安装路径
[root@hadoop105 nginx-1.12.2]# whereis nginx
nginx: /usr/local/nginx /usr/local/nginx/sbin/nginx
//让nginx生效
vim /etc/profile
# Nginx
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
source /etc/profile
(3)进入配置文件
[root@hadoop105 nginx-1.12.2]# cd conf
[root@hadoop105 conf]# ll
total 36
-rw-r--r--. 1 1001 1001 1077 Oct 17 2017 fastcgi.conf
-rw-r--r--. 1 1001 1001 1007 Oct 17 2017 fastcgi_params
-rw-r--r--. 1 1001 1001 2837 Oct 17 2017 koi-utf
-rw-r--r--. 1 1001 1001 2223 Oct 17 2017 koi-win
-rw-r--r--. 1 1001 1001 3957 Oct 17 2017 mime.types
-rw-r--r--. 1 1001 1001 2656 Oct 17 2017 nginx.conf
-rw-r--r--. 1 1001 1001 636 Oct 17 2017 scgi_params
-rw-r--r--. 1 1001 1001 664 Oct 17 2017 uwsgi_params
-rw-r--r--. 1 1001 1001 3610 Oct 17 2017 win-utf
//查看nginx.conf配置
[root@hadoop105 conf]# vim nginx.conf
//改变参数:
upstream logserver {
server hadoop105:8080 weight=1;
server hadoop106:8080 weight=1;
server hadoop107:8080 weight=1;
}
server {
listen 80;
server_name logserver;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://logserver;
proxy_connect_time 10;
}
nginx参数图:
(4)启动
//进入sbin文件目录下
[root@hadoop105 conf]# cd /usr/local/nginx/sbin
[root@hadoop105 sbin]# ll
total 3576
-rwxr-xr-x. 1 root root 3659872 Feb 15 17:16 nginx
//启动命令
[root@hadoop105 sbin]# ./nginx
//查看进程
[root@hadoop105 sbin]# ps aux|grep nginx
root 25467 0.0 0.0 20536 624 ? Ss 06:44 0:00 nginx: master process ./nginx
nobody 25468 0.0 0.1 20984 1324 ? S 06:44 0:00 nginx: worker process
root 25470 0.0 0.0 112712 964 pts/2 R+ 06:45 0:00 grep --color=auto nginx