Nginx 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。
想要Linux下安装Nginx作为WEB服务器,要先准备些必要的库和工具,通常必须安装的是:PERC库和Openssl。
1. 安装PCRE库(Nginx的rewrite模块和HTTP核心模块会用到PCRE正则表达式语法)
使用yum来安装:
yum install pcre pcre-devel
2.安装OpenSSL(若服务器提供安全网页(https://)时,会用到OpenSSL库)
# yum install openssl openssl-devel
3.下载、解压Nginx
去http://nginx.org/下载你要使用的版本,放到home目录,然后解压
# tar zxf nginx-1.12.2.tar.gz
4.安装Nginx
创建一个应用程序通常分为三步:从源代码到配置、编译和安装编译
需要使用root用户安装
1) 进入解压完的nginx目录,执行下面命令
./configure --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
2)root# make3)root# make install
默认安装位置在 /usr/local/nginx
5.启动和停止Nginx
进入/usr/local/nginx/sbin/ ,执行 nginx 即可启动
停止时 使用 nginx -s stop命令
6.配置Nginx.conf
如果要使用nginx做负载均衡,一般要单独配置conf文件。
1)新建一个 name为 webapp.conf 的配置文件,内容如下:
upstream backend {
server ip1:8000;
server ip2:8000;
}
server {
listen 80;
location /web {
proxy_pass http://backend;
}
}
2) 修改conf目录下的nginx.conf文件
在 include mime.types;
之后增加 include webapp.conf;
将 包含80端口的 server {
xxxxxxxxx
}
给注释掉。
3) 先 执行 nginx -s stop 停止,再执行 nginx 启动。
4) 在浏览器中 执行 localhost/web ,即可 将请求转发至配置好的2台app服务器上。
具体的配置信息可以参考一下的博客
https://www.cnblogs.com/Steward-Xu/p/6703295.html
https://blog.youkuaiyun.com/daybreak1209/article/details/51554045