环境描述:虚拟机准备两台,一台作为nginx服务器+mysql服务器,IP为:192.168.55.129;另外一台作为2台Tomcat服务器,IP为:192.168.55.130。客户端发来请求,首先由nginx处理,如果为静态内容直接由nginx响应,将结果直接给客户端;如果为动态内容,则由nginx反代至后端的Tomcat服务器。
在IP为192.168.55.129的服务器上安装和配置nginx关闭防火墙和selinux
[root@yanyinglai ~]# systemctl stop firewalld
[root@yanyinglai ~]# systemctl disable firewalld
[root@yanyinglai ~]# setenforce 0
[root@yanyinglai ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
创建系统用户nginx
[root@yanyinglai ~]# useradd -r -M -s /sbin/nologin nginx
安装依赖环境
[root@yanyinglai ~]# yum -y install pcre-devel openssl openssl-devel gd-devel
[root@yanyinglai ~]# yum -y groups install 'Development Tools'
创建日志存放目录
[root@yanyinglai ~]# mkdir -p /var/log/nginx
[root@yanyinglai ~]# chown -R nginx.nginx /var/log/nginx/
下载nginx
[root@yanyinglai ~]# cd /usr/src/
[root@yanyinglai src]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
编译安装
[root@yanyinglai ~]# cd /usr/src/
[root@yanyinglai src]# ls
debug kernels nginx-1.14.0.tar.gz
[root@yanyinglai src]# tar xf nginx-1.14.0.tar.gz
[root@yanyinglai src]# cd nginx-1.14.0
[root@yanyinglai nginx-1.14.0]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
[root@yanyinglai nginx-1.14.0]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-debug \
> --with-http_ssl_module \
> --with-http_realip_module \
> --with-http_image_filter_module \
> --with-http_gunzip_module \
> --with-http_gzip_static_module \
> --with-http_stub_status_module \
> --http-log-path=/var/log/nginx/access.log \
> --error-log-path=/var/log/nginx/error.log
[root@yxr nginx-1.12.0]# make -j 2 && make install
nginx安装后配置配置环境变量
[root@yanyinglai nginx-1.14.0]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@yanyinglai nginx-1.14.0]# . /etc/profile.d/nginx.sh
启动nginx
[root@yanyinglai nginx-1.14.0]# nginx
[root@yanyinglai nginx-1.14.0]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
在IP为192.168.55.129上安装mysql
安装依赖包
[root@yanyinglai ~]# yum -y install ncurses-devel openssl-devel openssl cmake mari