nginx如何实现负载均衡和反向代理?
Admin 2023-05-15 群英技术资讯 1379 次浏览
这篇文章主要讲解了“nginx如何实现负载均衡和反向代理?”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“nginx如何实现负载均衡和反向代理?”吧!vim /etc/inittab id:5:initdefault: --> 修改5为3
若要界面启动使用 startx
1)解压:jdk-7u55-linux-i586.tar.gz
[root@localhost jdk]# tar -zxvf jdk-7u55-linux-i586.tar.gz
2)复制:[root@localhost jdk]# cp -rf jdk1.7.0_55/ /usr/local/jdk
授权:[root@localhost jdk]# cd /usr/local/jdk
[root@localhost jdk]# chmod u+x jdk/
3)配置环境;[root@localhost bin]# vim /etc/profile
最后面插入:export JAVA_HOME=/usr/local/jdk/jdk1.7.0_79
export PATH=$JAVA_HOME/bin:$PATH
4)刷新配置文件:source /etc/profile
验证:java javac
1)解压:tar -zxvf
2)授权:chmod u+x/usr/local/tomcats/tomcat1/apache-tomcat-7.0.47/bin
3)启动:进入tomcat目录bin 目录后: ./startup.sh
4)开放端口:vim /etc/sysconfig/iptables
5)关闭防火墙:chkconfig iptables off
6)重启防火墙: service iptables restart
7)修改端口号:vim conf/server.xml
8)查看进程:ps aux | grep tomcat
1)安装环境:
yum -y install gcc-c++
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
2)解压:tar -zxvf nginx-1.8.0.tar.gz
3)创建安装目录:[root@localhost local]# mkdir -p nginx
[root@localhost local]# cd nginx/
[root@localhost nginx]# pwd
/usr/local/nginx
4)创建临时目录:var]# mkdir -p temp/nginx
5)进入目录:cd nginx-1.8.0/
6)修改参数:
./configure \
--prefix=/usr/local/nginx \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/nginx/client \ --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ --http-scgi-temp-path=/var/temp/nginx/scgi
7)编译安装:
make
make install
8)启动: cd /usr/local/nginx/sbin/
./nginx
9)查看进程:ps aux | grep nginx
10)快速停止:./nginx -s stop
11)完整停止:./nginx -s quit 此方式停止步骤是待nginx进程处理任务完毕进行停止。推荐使用
12)重启: ./nginx -s quit
./nginx
13)重新加载配置文件: ./nginx -s reload
1、nginx支持的三种虚拟主机的配置:
基于ip的虚拟主机
基于域名的虚拟主机
基于端口的虚拟主机
2、nginx配置文件的结构: 每个service就是一个虚拟主机
......
events{
......
}
http{
.......
server{
......
}
server{
......
}
}
3、基于ip的虚拟主机配置:
修改配置文件: vim /usr/local/nginx/nginx-1.8.0/conf/nginx.conf
server{
listen 80;
server_name 192.168.31.88;
location / {
root html;
index index.html index.htm;
}
}
4、基于域名的虚拟主机配置:
修改配置文件:vim /usr/local/nginx/nginx-1.8.0/conf/nginx.conf
server{
listen 80;
server_name www.nginxdns1.com;
location / {
root html_dns1;
index index.html index.htm;
}
}
server{
listen 80;
server_name www.nginxdns2.com;
location / {
root html_dns2;
index index.html index.htm;
}
}
5、基于端口的虚拟主机配置:
修改配置文件:vim /usr/local/nginx/nginx-1.8.0/conf/nginx.conf
监听端口:netstat -an | grep 80
server{
listen 88;
server_name 192.168.31.88;
location / {
root html_port1;
index index.html index.htm;
}
}
server{
listen 89;
server_name 192.168.31.88;
location / {
root html_port2;
index index.html index.htm;
}
}
修改hosts:# nginx反向代理环境测试
192.168.31.88 www.nginxproxy1.com
192.168.31.88 www.nginxproxy2.com
开启不同虚拟机中的两台tomcat:192.168.31.88:8080 和 192.168.31.89:8081
修改配置文件:
#代理tomcat1服务器
upstream tomcat_server1{
server 192.168.31.89:8081;
}
#代理tomcat2服务器
upstream tomcat_server2{
server 192.168.31.88:8080;
}
#配置虚拟主机:
server{
listen 80;
server_name www.nginxproxy1.com;
location / {
#root html_port1;
proxy_pass http://tomcat_server1;
index index.html index.htm;
}
}
server{
listen 80;
server_name www.nginxproxy2.com;
location / {
#root html_port2;
proxy_pass http://tomcat_server2;
index index.html index.htm;
}
}
修改hosts :# nginx负载均衡环境测试
192.168.31.88 www.nginxbalance.com
开启不同虚拟机中的两台tomcat:192.168.31.88:8080 和 192.168.31.89:8081
修改配置文件:
#代理tomcat2服务器
upstream tomcat_server_pool{
server 192.168.31.88:8080 weight=1;
server 192.168.31.89:8081 weight=1;
}
#配置虚拟主机:
server{
listen 80;
server_name www.nginxbalance.com;
location / {
#root html_port1;
proxy_pass http://tomcat_server_pool;
index index.html index.htm;
}
}
192.168.31.88 www.nginxdns1.com 192.168.31.88 www.nginxdns2.com
192.168.31.88 www.nginxproxy1.com 192.168.31.88 www.nginxproxy2.com
192.168.31.88 www.nginxbalance.com
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
CentOS服务器下使用Nginx实现Impala负载均衡
linux下的文件重命名命令是mv。mv命令用来为文件或目录改名或将文件由一个目录移入另一个目录中,例如【$ mv test.txt wbk.txt】,表示将文件test重命名为webk。
在linux中,可以利用find命令的“-prune”参数使find在查找文件时不查找指定子目录,find命令用来在指定目录下查找文件,当参数设置为“-prune”时可以进行过滤,只需将要忽略的路径参数必须紧跟着搜索的路径之后,否则该参数无法起作用,语法为“find 搜索路径 -path 不查找的子目录路径 -prune...”。
方法:1、直接在linux命令行页面输入“export PATH=/usr/local/sbin...”,导入环境变量;2、用绝对命令vi打开profile,语法为/bin/vi /etc/profile”,并在配置文件内添加环境变量地址。
linux下怎样实现删除指定文件?有时候我只是想要删除指定的文件,但是子目录里面有些可能有很多个样的文件名,如果我们一个个进行删除,那么效率低而且也麻烦。下面小编就给大家分享一下个高效便捷的删除指定文件的方法,感兴趣的朋友就继续看吧。
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008