部落法师a怪升级路线:nginx 负载均衡配置
来源:百度文库 编辑:九乡新闻网 时间:2024/04/28 23:05:42
Nginx 简介
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。 Igor 将源代码以类 BSD 许可证的形式发布。尽管还是测试版,但是,Nginx 已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。
为了确保能在 Nginx 中使用正则表达式进行更灵活的配置,安装之前需要确定系统是否安装有 PCRE ./configure
make
make install
安装完成之后 安装 nginx
./configure --with-http_stub_status_module –prefix=/usr/local/nginx
make
make install
就这样nginx 安装完成 启动nginx 命令如下 ./nginx & 如果通过http://localhost 能够访问的话 表示安装成功 /如图:
安装成功后 /usr/local/nginx 目录下有四个子目录分别是:conf、html、logs、sbin 。其中 Nginx 的配置文件存放于 conf/nginx.conf,Nginx 只有一个程序文件位于 sbin 目录下的 nginx 文件。
打开nginx.conf配置文件 修改后内容如下:
#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 {
use epoll;#linux
worker_connections 2048;
}
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;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream mao{
server 192.168.0.208:8080 weight=2;
server 192.168.0.235 weight=3;
}
server {
listen 80;
server_name www.today.com;
charset utf-8;
#access_log logs/host.access.log main;
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov) {
access_log off; # po co mi logi obrazków :)
expires 30d;
}
location ~ ^/(WEB-INF)/ {
deny all;
}
location /NginxStatus/ {
stub_status on; #Nginx 状态监控配置
access_log off;
}
location /they{
proxy_pass http://mao;# 反向代理
使用 Nginx 前必须了解的事项
- 目前官方 Nginx 并不支持 Windows,您只能在包括 Linux、UNIX、BSD 系统下安装和使用;
- Nginx 本身只是一个 HTTP 和反向代理服务器,它无法像 Apache 一样通过安装各种模块来支持不同的页面脚本,例如 PHP、CGI 等;
- Nginx 支持简单的负载均衡和容错;
- 支持作为基本 HTTP 服务器的功能,例如日志、压缩、Byte ranges、Chunked responses、SSL、虚拟主机等等,应有尽有
安装完成之后 安装 nginx
./configure --with-http_stub_status_module –prefix=/usr/local/nginx
make
make install
就这样nginx 安装完成 启动nginx 命令如下 ./nginx & 如果通过http://localhost 能够访问的话 表示安装成功 /如图:
安装成功后 /usr/local/nginx 目录下有四个子目录分别是:conf、html、logs、sbin 。其中 Nginx 的配置文件存放于 conf/nginx.conf,Nginx 只有一个程序文件位于 sbin 目录下的 nginx 文件。
打开nginx.conf配置文件 修改后内容如下:
#user
worker_processes
#error_log
#error_log
#error_log
#pid
events {
}
http {
}