用戶訪問http://www.net-hb.com.cn,將其負載均衡到192.168.1.2:80、192.168.1.3:80、192.168.1.4:80、192.168.1.5:80四臺服務器。
用戶訪問//www.zmynmublwnt.cn,將其負載均衡到192.168.1.7服務器的8080、8081、8082端口。
以下為配置文件nginx.conf:
引用
[table=95%][tr][td]user www www;
worker_processes 10;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
#最大文件描述符
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include conf/mime.types;
default_type application/octet-stream;
keepalive_timeout 120;
tcp_nodelay on;
upstream www.net-hb.com.cn {
server 192.168.1.2:80;
server 192.168.1.3:80;
server 192.168.1.4:80;
server 192.168.1.5:80;
}
upstream blog.s135.com {
server 192.168.1.7:8080;
server 192.168.1.7:8081;
server 192.168.1.7:8082;
}
server
{
listen 80;
server_name www.net-hb.com.cn;
location / {
proxy_pass http://www.net-hb.com.cn;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
log_format www_s135_com '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /data1/logs/www.log www_s135_com;
}
server
{
listen 80;
server_name blog.s135.com;
location / {
proxy_pass //www.zmynmublwnt.cn;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
log_format blog_s135_com '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /data1/logs/blog.log blog_s135_com;
}
}[/td][/tr][/table] 附:Nginx 的安裝方法可參照《Nginx 0.5.31 + PHP 5.2.4(FastCGI)搭建可承受3萬以上并發連接數,勝過Apache 10倍的Web服務器》文章的以下段落(僅做負載均衡,無需支持PHP的安裝方法):
二、安裝PHP 5.2.4(FastCGI模式)
4、創建www用戶和組,以及其使用的目錄:
三、安裝Nginx 0.5.31
1、安裝Nginx所需的pcre庫:
2、安裝Nginx
3、創建Nginx日志目錄
5、啟動Nginx
Nginx 簡單的負載均衡配置示例
2019-10-07 19:14服務器之家 Nginx
Nginx 簡單的負載均衡配置示例,需要的朋友可以參考下。
延伸 · 閱讀
- 2022-03-10基于nginx反向代理獲取用戶真實Ip地址詳解
- 2022-03-10Linux服務器下安裝配置Nginx的教程
- 2022-03-10在Linux里安裝和啟動nginx的方法
- 2022-03-09在lnmp環境中的nginx編譯安裝
- 2022-03-08CentOS6.5系統簡單安裝與配置Nginx服務器的方法
- 2022-03-07ELK監控nginx日志總結
- Nginx
Nginx配合php實現生成實時縮略圖功能
這篇文章主要介紹了Nginx配合php實現生成實時縮略圖功能,這在一些特殊場合可能會要用到,需要的朋友可以參考下 ...
- Nginx
Linux服務器nginx訪問日志里出現大量http 400錯誤的請求分析
這篇文章主要介紹了Linux服務器nginx訪問日志里出現大量http 400錯誤的請求分析,需要的朋友可以參考下...
- Nginx
學習nginx基礎知識
這篇文章主要介紹了nginx基礎知識,文中運用了大量的圖片和代碼進行講解,對相關知識感興趣的小伙伴可以參考一下這篇文章...
- Nginx
采用ngxtop實現nginx實時訪問數據統計
這篇文章主要介紹了采用ngxtop實現nginx實時訪問數據統計,需要的朋友可以參考下 ...
- Nginx
windows10 系統配置nginx文件服務器的圖文教程
這篇文章主要介紹了windows10 系統配置nginx文件服務器的圖文教程,本文圖文并茂給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下...
- Nginx
Nginx服務器中HTTP 301跳轉到帶www的域名的方法
這篇文章主要介紹了Nginx服務器中HTTP 301跳轉到帶www的域名的方法,包括從HTTPS 301提示跳轉等rewrite相關的方法,需要的朋友可以參考下 ...
- Nginx
使用Nginx代理上網的方法
這篇文章主要介紹了使用Nginx代理上網的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨...
- Nginx
Nginx域名轉發使用場景代碼實例
這篇文章主要介紹了Nginx域名轉發使用場景代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參...