nginx 负载
准备服务器、域名、nginx程序
服务器A:47.104.238.XX
服务器B:39.105.126.XX
域名:fz213.xxx.top
nginx下载地址:http://nginx.org/en/download.html
实现思路:域名的A记录指向服务器A,在服务器A上部署nginx,然后访问域名,重新跳转A或B服务器
1、配置nginx.conf文件
配置的主要思路:访问域名时,通过域名解析的A记录,找到对应的服务器,nginx此时捕获,走nginx配置文件,通过配置中的端口监控匹配对应的规则,转发到对应的服务器及端口
a、在server节点上面增加upstream
8032、8016分别对应的是网站的端口
upstream iis.temp.fz.2021{ server 39.105.126.xx:8032 weight=1; server 47.104.238.xx:8016 weight=1; } |
b、在server中配置监听端口,服务器名称
由于80端口冲突,这里监听8017端口
listen 8017; server_name fz213.xxx.top; |
c、路由中配置upstream名称
location / { proxy_pass http: //iis.temp.fz.2021; } |
完整配置:
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include 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 logs/access.log main; sendfile on ; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream iis.temp.fz.2021{ server 39.105.126.xx:8032 weight=1; server 47.104.238.xx:8016 weight=1; } server { listen 8017; server_name fz213.xxx.top; #charset koi8-r; #access_log logs/host.access.log main; location / { #root html; #index index.html index.htm; proxy_pass http: //iis.temp.fz.2021; } #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 html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} } |
2、启动nginx
3、访问地址即可
此时由于监控的是8017端口,所以域名后面需要加上8017
即:fz213.xxx.top:8017
去掉端口的访问方法:https://www.cnblogs.com/xiao-sheng/p/15415377.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)