时间:2021-07-01 10:21:17 帮助过:22人阅读
1.配置nginx安装源
vim /etc/yum.repos.d/nginx.repo [nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
2.安装nginx
如已安装了nginx,需要升级,执行update即可
yum update nginx
如未安装,执行如下命令,安装即可
yum install nginx -y
nginx -v //查看版本
3.查看nginx的安装目录
whereis nginx
4.编辑nginx配置文件
cd /etc/nginx
vim nginx.conf
在此,附上nginx.conf的源码:
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }从上面可以看出,还调用了/etc/nginx.conf.d/*.conf文件
再附上default.conf源码:
upstream school { server 192.168.1.103:80; server 192.168.1.100:8080; server 192.168.1.101:80; } server { listen 80; server_name school; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { # root /usr/share/nginx/html; proxy_pass http://school; # index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }如此一来,就完成了3台服务器的简单负载了。
5.测试nginx配置是否正确
nginx -t
都显示的ok和successful表示配置没得什么问题
6.启动nginx
启动下nginx就可以了
service nginx start
再输入nginx的地址测试一下:
由此看出,每执行一次,所到达的tomcat服务都是不一样的,OK!大功告成!!!
以上就介绍了采用nginx让多个tomcat实现负载均衡,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。