文章目录
1. nginx中location应用实例
location是nginx的精华,nginx就是通过拦截到的请求去对配置好的location块(location block)进行请求代理的。
location是用来具体配置代理路径的。
2. nginx反向代理应用实例
(1)节点部署
准备两台测试服务器,web1和web2
主机名 | IP |
---|---|
nginx | 192.168.10.11 |
web1 | 192.168.10.102 |
web2 | 192.168.10.103 |
(2)处理防火墙(三个节点)
[root@nginx ~]# systemctl stop firewalld
[root@nginx ~]# systemctl disable firewalld
[root@nginx ~]# setenforce 0
(3)同步时钟源(三个节点)
[root@nginx ~]# yum install ntp ntpdate -y
[root@nginx ~]# ntpdate ntp1.aliyun.com
[root@nginx ~]# clock -w
(4)web端安装httpd
# web1
[root@web1 ~]# yum install httpd -y
[root@web1 ~]# echo "<h1>web1.test.com</h1>" > /var/www/html/index.html
[root@web1 ~]# systemctl start httpd
# web2
[root@web2 ~]# yum install httpd -y
[root@web2 ~]# echo "<h1>web2.test.com</h1>" > /var/www/html/index.html
[root@web2 ~]# systemctl start httpd
(5)安装nginx
[root@nginx ~]# useradd nginx
[root@nginx ~]# wget http://nginx.org/download/nginx-1.15.0.tar.gz
[root@nginx ~]# yum install gcc gcc-c++ make pcre-devel openssl openssl