首先假定你已安装好Nginx,并切换到Nginx的安装目录,执行补丁操作,并进行安装:
1. 要实现openfire负载,需要添加nginx nginx_tcp_proxy_module模块
编译nginx_tcp_proxy_module:
下载: 我将下载文件存放在 /usr/local/src/ 下
wget https://github.com/yaoweibin/nginx_tcp_proxy_module/archive/master.zip
2.编译添加的 nginx_tcp_proxy_module模块
patch -p1 < /usr/local/src/nginx_tcp_proxy_module/tcp.patch
./configure --add-module=/usr/local/src/nginx_tcp_proxy_module/
make
make install
如果系统没有安装patch,需要安装,如果安装测忽略。
yum install patch
3. 修改配置文件nginx.conf:
user root;
worker_processes 4;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 10240;
}
tcp {
timeout 1d;
proxy_read_timeout 10d;
proxy_send_timeout 10d;
proxy_connect_timeout 30;
upstream openfire5222{
server 192.168.2.189:5222;
server 192.168.2.188:5222;
}
server{
listen 5222;
proxy_pass openfire5222;
so_keepalive on;
tcp_nodelay on;
}
upstream openfire5223{
server 192.168.2.189:5223;
server 192.168.2.188:5223;
}
server{
listen 5223;
proxy_pass openfire5223;
so_keepalive on;
tcp_nodelay on;
}
}
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 openfire7070{
server 192.168.2.189:7070;
server 192.168.2.188:7070;
}
server{
listen 7070;
server_name 192.168.2.191;
location / {
proxy_pass http://openfire7070;
}
}
upstream openfire9090{
server 192.168.2.189:9090;
server 192.168.2.188:9090;
ip_hash;
}
server {
listen 9090;
server_name localhost;
location / {
proxy_pass http://openfire9090;
}
}
server {
listen 8086;
server_name 192.168.2.191;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /status{
tcp_check_status;
}
#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://go.rritw.com/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;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
4: 访问:http://192.168.2.191:9090/login.jsp?url=%2Findex.jsp 进行验证。