若系统上已安装编译所需要的工具,第一、二步可跳过,可通过yum list installed 查看
1、安装编译工具及库文件
yum -y install make zlib zlib-devel gcc libtool openssl openssl-devel
2、安装PCRE,让NGINX支持Rewrite功能
yum install pcre
3、下载并解压安装包
//创建一个文件夹
cd /usr/local
注:
非 root 权限用户无法创建
(若非 root 权限,在可操作的文件加下创建 ./configure时需要配置 --prefix )
cd /webapp/billing
mkdir nginx
cd nginx
//下载tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz(若不能在线安装,去官网手动下载,并上传到服务器)
tar -xvf nginx-1.13.7.tar.gz
4、安装nginx
//进入nginx目录
cd /webapp/billing/nginx
//执行命令
./configure --prefix=/webapp/billing/nginx(否则会默认编译到 /usr/local/ngnix 中,应用户为非 root 权限用户,导致 make install 时没有权限)
//执行make命令
make
//执行make install命令
make install
5、配置nginx.conf
# 打开配置文件
vi /webapp/billing/nginx/conf/nginx.conf
#服务器集群
upstream springbootNginx2 {
server 134.32.51.64:28081 weight=10 max_fails=1 fail_timeout=30s;
#server 134.32.51.64:28083 weight=10;
}
server {
listen 8095;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#root html;
#index index.html index.htm;
proxy_pass http://springbootNginx2;
}
6、启动nginx,启动后,可通过/webapp/billing/nginx/logs 中的 nginx.pid 查看端口号
/webapp/billing/nginx/sbin/nginx
7、重启 nginx
/webapp/billing/nginx/sbin/nginx -s reload
8、关闭 nginx
./nginx -s stop 关闭