JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

反向代理(Nginx) 反向代理和负载均衡的区别

wys521 2024-10-04 06:15:54 精选教程 16 ℃ 0 评论

需求


安装LNMP

web1和web2都要做,这里只演示web2

[root@web2 ~]# tar -xf nginx-1.12.2.tar.gz(先解压)

使用yum安装基础依赖包

1. [root@web2 ~]# yum -y install gcc openssl-devel pcre-devel

安装MariaDB

1. [root@web2 ~]# yum -y install mariadb mariadb-server mariadb-devel

php和php-fpm

1. [root@web2 ~]# yum -y install php php-mysql

2. [root@web2 ~]# yum -y install php-fpm

进入解压后的nginx,执行./configure,添加两个模块。

[root@web2 nginx-1.12.2]# make && make install(编译安装)

[root@web1 nginx-1.12.2]# vim /usr/local/nginx/conf/nginx.conf(进入配置文件修改配置)

[root@web2 ~]# systemctl enable mariadb --now(启动数据库并设置开机自启)

[root@web1 nginx-1.12.2]# ss -antlp(查看端口的命令)

创建PHP测试页面,连接并查询MariaDB数据库。在web1的html下面创建一个test.php

七层代理(在两台代理服务器上做)

1. [rootagent ~]# cd nginx-1.12.2

[root@agent nginx-1.12.2]# ./configure(只需执行这个)

[root@agent nginx-1.12.2]# make && make install

[root@agent ~]# /usr/local/nginx/sbin/nginx(启动nginx)

测试

区分两个为不同的页面

[root@web2 html]# echo "BBB" > /usr/local/nginx/html/index.html

[root@web1 ~]# echo "AAA" > /usr/local/nginx/html/index.html

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表