ubuntu 安装nginx
源码安装
gcc、g++依赖库
apt-get install build-essential
apt-get install libtool
安装 pcre依赖库
sudo apt-get install libpcre3 libpcre3-dev
下载源码包,安装
./configure
make
make install
注意问题:
在执行configure的时候注意nginx的一些默认配置路径,例如:
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
当然也可以把nginx命令放入path系统变量中。
配置文件 nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
错误日志 nginx error log file: "/usr/local/nginx/logs/error.log"
访问日志 nginx http access log file: "/usr/local/nginx/logs/access.log"
基于Nginx的jetty实现负载均衡
Nginx 配置upstream实现负载均衡
情景:在一台物理机器上{本地环境是ubuntu16}使用1个Nginx服务和2个jetty服务搭建了一个负载均衡的小环境。
关键步骤如下;
1、nginx的配置文件添加upstream节点来实现负载均衡。
upstream linuxidc {
server 127.0.0.1:8081;
server 127.0.0.1:8082;
}
location / {
root html;
index index.html index.htm;
proxy_pass http://linuxidc;
}
2、将项目部署到jetty中,由于是在一台机器上部署2个jetty,所以需要修改jetty的默认端口,在jetty的home目录下的start.ini配置文件中修改
#jetty.http.port=8080
注意将其注释#去掉,并修改成自定义端口。然后就是正常启动服务,将项目部署到webapp的目录下。
结论:
1、当8081端口和8082端口正常启动的时候,2个端口服务均可以被正常的访问到。
2、当其中一个端口服务停止的时候,另外的一个端口服务依然可以提供服务。
3、可以在一台机器上面,使用nginx对不同的jetty的端口服务做负载均衡。