您的位置:首页 > 运维架构 > 反向代理

Nginx 反向代理基本框架

2020-02-16 03:12 302 查看

全局配置指令:
user nginx;

模块配置段
# 事件驱动模块,提供并发响应功能
events{
......
}
# http模块,提供web请求处理,可嵌套其他重要模块
http{
.......#server{}
}

开始配置:#备份nginx.conf ,清空文件
# vim /etc/hosts 增加主机记录
vim /etc/nginx/nginx.conf

worker_processes 2; # 两个nginx进程
events {
worker_connections 1024; # 可同时处理1024个http请求
}

http {
include mime.types; #调用mime ,可以处理多媒体
default_type application/octet-stream;

upstream test {
# ip_hash; # 基于客户端的hash值进行请求分配
server test1.com weight=10; # 权重负载
server test2.com weight=20;
}

server {
listen 80;
server_name afan.com; # 用户输入网页先匹配到server{}中
location / {
proxy_pass http://test/index.html; # 扔给后端服务器,
# html 是upstream的引用,先扔给 upstream html{}模块
}
}

#############################################3
server { #nginx至少有个虚拟主机才能工作
listen 80;
server_name Localhost; # 虚拟主机名称
access_log /var/log/nginx/access_html.log html_log; #若localtion中,优先
root html; # 网站主目录 ,一般是配置文件所在的目录

location{}

}
}

# 压力测试:# while true; do curl afan.com;done
# shell : for i in `seq 1 20` ;do
curl afan.com
sleep 0.5
done

 

转载于:https://www.cnblogs.com/wanzf/p/10654099.html

  • 点赞
  • 收藏
  • 分享
  • 文章举报
dianhang5567 发布了0 篇原创文章 · 获赞 0 · 访问量 209 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: