常规的web服务器一般提供对于静态资源的访问,比如说:图片、web样式
网站提供的大部分交互功能都需要web编程语言的支持,而web服务对于程序的调用,不管编译型语言还是解释型语言,web服务同将对于应用程序的调用递交给通用网关接口(CGI)。CGI 服务完成对于程序的调用和运行,并将运行结构通过CGI接口返回给web服务,由web服务生成响应报文。
此时在web服务的领域内,引入了LAMP等较为知名的web架构,使web页面提供应用服务成为一种可能,
随着web网站的发展,基本的web服务器容易出现性能瓶颈、响应缓慢等问题,为了解决这些问题,人们尝试通过一些技术手段解决这个问题,这一类技术都属于负载均衡技术,常用于进行负载均衡的服务有:HAProxy、Nginx、lvs等。除此之外,还可以结合dns负载均衡等技术,即一个域名映射多个IP地址等方式。
一、nginx 负载均衡实验
nginx 负载均衡实验过程整理如下:
[root@bogon ~]# systemctl disable --now httpd // 确保80端口未被httpd 占用
[root@bogon ~]# systemctl start nginx.service // 启动nginx 服务
[root@bogon ~]# ps -elf | grep nginx
1 S root 5825 1 0 80 0 - 2875 sigsus 14:47 ? 00:00:00 nginx: master process /usr/sbin/nginx
5 S nginx 5826 5825 0 80 0 - 3964 ep_pol 14:47 ? 00:00:00 nginx: worker process
5 S nginx 5827 5825 0 80 0 - 3964 ep_pol 14:47 ? 00:00:00 nginx: worker process
0 S root 5833 2362 0 80 0 - 55417 pipe_r 14:47 pts/0 00:00:00 grep --color=auto nginx
// 恢复成默认的主配置文件,如果之前没有备份,可以使用在/etc/nginx/nginx.default 来恢复,略有不同,影响不大
[root@bogon ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf_$(date +%s) //备份当前配置文件
[root@bogon ~]# cp /etc/nginx/nginx.conf_1724661958 /etc/nginx/nginx.conf // 恢复默认配置0
cp: overwrite '/etc/nginx/nginx.conf'? y
[root@bogon ~]# vim /etc/nginx/nginx.conf // 暂时无需修改,额外的配置放在conf.d 目录下
[root@bogon ~]# ls /etc/nginx/conf.d/
[root@bogon ~]# vim /etc/nginx/conf.d/real_web.conf // 这是一个新文件,全部内容如下:
server {
listen 81;
server_name web1;
root /usr/share/nginx/real1;
index index