2019-05-31 15:29:26 3541浏览
今天千锋扣丁学堂Linux培训老师给大家分享一篇关于Nginx反向代理与负载均衡,是面试加分项没有之一,首先越来越多的程序员开始学习更多的IT语言,下面就直接来说一下主题吧,前端要了解一些运维的Nginx用法,内容不多,简单看看就好,这两个功能在工作当中就够用了,那么首先来看个问题,什么是反向代理与负载均衡。
安装nginx
1-进到homebrew官网,然后复制命令,预安装需要的东西
2-brew install nginx 安装nginx
3-nginx -v 显示版本号
进入nginx
cd /usr/local/etc/nginx
下图为进入nginx文件夹下的文件内容
当你敲完nginx这5个键的时候,并没有任何反应,此时你只需访问localhost:8080(默认)即可
然后再次启动nginx即可
nginx:the configuration file/usr/local/etc/nginx/nginx.conf syntaxisok nginx:configuration file/usr/local/etc/nginx/nginx.conf testissuccessful
server {
listen 80;
location / {
proxy_pass http://10.10.10.10:20186;
}
}
// 修改nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
upstream firstdemo {
server 39.106.145.33;
server 47.93.6.93;
}
server {
listen 8080;
location / {
proxy_pass http://firstdemo;
}
}
}
那么再次访问localhost:8080,会看到如下图页面
还有另一个页面
// 省略...
upstream firstdemo {
ip_hash;
server 39.106.145.33;
server 47.93.6.93;
}
server {
listen 80;
server_name chd.news.so.m.qss.test.so.com ;
auth_basic off;
location / {
proxy_pass http://10.10.10.10:20186;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 60;
proxy_read_timeout 600;
proxy_send_timeout 600;
}
}
【关注微信公众号获取更多学习资料】 【扫码进入HTML5前端开发VIP免费公开课】