nginx 负载均衡
程序员文章站
2022-06-15 14:28:57
...
www.s135.com 和 blog.s135.com 域名均指向 Nginx 所在的服务器IP。 用户访问 http://www.s135.com ,将其 负载 均衡 到192.168.1.2:80、192.168.1.3:80、192.168.1.4:80、192.168.1.5:80四台服务器。 用户访问 http://blog.s135.com ,将其 负载 均衡 到192
www.s135.com 和 blog.s135.com 域名均指向 Nginx 所在的服务器IP。
用户访问http://www.s135.com,将其负载均衡到192.168.1.2:80、192.168.1.3:80、192.168.1.4:80、192.168.1.5:80四台服务器。
用户访问http://blog.s135.com,将其负载均衡到192.168.1.7服务器的8080、8081、8082端口。
以下为配置文件nginx.conf:
用户访问http://www.s135.com,将其负载均衡到192.168.1.2:80、192.168.1.3:80、192.168.1.4:80、192.168.1.5:80四台服务器。
用户访问http://blog.s135.com,将其负载均衡到192.168.1.7服务器的8080、8081、8082端口。
以下为配置文件nginx.conf:
引用
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.s135.com {
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.s135.com;
location / {
proxy_pass http://www.s135.com;
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 http://blog.s135.com;
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;
}
}
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.s135.com {
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.s135.com;
location / {
proxy_pass http://www.s135.com;
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 http://blog.s135.com;
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;
}
}
上一篇: MySQL数据库管理员普遍疑难汇总(1)_MySQL
下一篇: LAMP装配后各部件的默认目录
推荐阅读
-
用 Gearman 散发 PHP 应用程序的工作负载
-
nginx+php-fpm组合解决PATHINFO最佳配置
-
Nginx跟PHP-FPM的启动/重启脚本
-
nginx学习心得
-
MySQL TroubleShoting:无任何操作、磁盘I/O负载跑满
-
Centos 6.5 搭建php环境(nginx+mariadb+php7)
-
图文详解Nginx版本平滑升级方案
-
nginx如何禁止文件上传目录执行PHP
-
配置Nginx多核CPU,worker_cpu_affinity使用方法和范例 affinity ds2 2 affinity 28 affinity
-
在Mac OS上搭建Nginx+PHP+MySQL开发环境的教程,