nginx常见应用实例

本文详细介绍了nginx的location配置、反向代理应用以及负载均衡的两种实现方式:weight轮询和ip_hash。通过实例展示了如何在多台服务器间进行请求分发,确保服务稳定和session的正确处理。
摘要由CSDN通过智能技术生成

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
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值