Linux环境下安装nginx
前往nginx官网下载
或者通过wget方式直接下载到服务器,以1.19.4版本为例
wget [http://nginx.org/download/nginx-1.19.4.tar.gz](http://nginx.org/download/nginx-1.19.4.tar.gz)
下载完成后解压,进入目录编译安装
#解压
tar zxvf nginx-1.19.4.tar.gz
#编译安装
./configure && make && make install
查找nginx安装到什么位置,默认安装在/usr/local/nginx
#查找nginx
whereis nginx
进入到nginx下的sbin目录中查看nginx的版本信息
./nginx -v
安装可能遇到的错误
错误为:./configure: error: the HTTP rewrite module requires the PCRE library.
#安装pcre-devel解决问题
yum -y install pcre-devel
#还有可能出现:
错误提示:./configure: error: the HTTP cache module requires md5 functions from OpenSSL library.
You can either disable the module by using --without-http-cache option,
or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using --with-http_ssl_module --with-openssl=<path> options.
#解决办法:
yum -y install openssl openssl-devel
为nginx配置环境变量
#编辑系统环境变量文件
vi /etc/profile
在文件末尾配置nginx的路径
重启环境变量设置
source /etc/profile
nginx常用命令
#启动
nginx
#重启
nginx -s reopen
#重新载入配置文件
nginx -s reload
#停止
nginx -s stop
Nginx是一款轻量级的Web服务器、反向代理服务器,由于它的内存占用少,启动极快,高并发能力强,在互联网项目中广泛应用。
架构图
上图基本上说明了当下流行的技术架构,其中Nginx有点入口网关的味道。
反向代理服务器?
经常听人说到一些术语,如反向代理,那么什么是反向代理,什么又是正向代理呢?
正向代理:
正向代理示意图
反向代理:
反向代理示意图
由于防火墙的原因,我们并不能直接访问谷歌,那么我们可以借助VPN来实现,这就是一个简单的正向代理的例子。这里你能够发现,正向代理“代理”的是客户端,而且客户端是知道目标的,而目标是不知道客户端是通过VPN访问的。
当我们在外网访问百度的时候,其实会进行一个转发,代理到内网去,这就是所谓的反向代理,即反向代理“代理”的是服务器端,而且这一个过程对于客户端而言是透明的。