安装类库
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
安装pcre
PCRE 作用是让 Ngnix 支持 Rewrite 功能。
1、下载 PCRE 安装包,下载地址:
http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
获取
[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
2、解压安装包:
[root@bogon src]# tar zxvf pcre-8.35.tar.gz
3、进入安装包目录
[root@bogon src]# cd pcre-8.35
4、编译安装
[root@bogon pcre-8.35]# ./configure
[root@bogon pcre-8.35]# make && make install
5、查看pcre版本
[root@bogon pcre-8.35]# pcre-config --version
安装 nginx_ upstream_ jvm_route
1、解压nginx-upstream-jvm-route-0.1.tar.gz
tar zxvf nginx-upstream-jvm-route-0.1.tar.gz
安装nginx
1、下载 Nginx、nginx-goodies-nginx-sticky-module-ng-08a395c66e42.zip,下载地址:http://nginx.org/download/nginx-1.6.2.tar.gz
[root@bogon src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
2、解压安装包
cd /opt/nginx/
tar zxvf nginx-1.11.6.tar.gz
unzip nginx-goodies-nginx-sticky-module-ng-08a395c66e42.zip
3、nginx-sticky-module用来保证同一个客户端访问的都是同一个后端服务器,重命名nginx-goodies-nginx-sticky-module-ng-08a395c66e42为nginx-sticky-module-ng
mv nginx-goodies-nginx-sticky-module-ng-08a395c66e42 nginx-sticky-module-ng
4、编译安装
cd nginx-1.6.2
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/opt/nginx/pcre-8.35 --add-module=/opt/nginx/nginx-sticky-module-ng
make
make install
5、将nginx执行文件加入path
[root@tjsw10 nginx]# vi /etc/profile
export PATH=$PATH:/usr/local/webserver/nginx/sbin/
[root@tjsw10 nginx]# source /etc/profile
6、查看nginx版本
[root@bogon nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v
nginx配置
创建 Nginx 运行使用的用户 nuser:
[root@bogon conf]# /usr/sbin/groupadd ngroup
[root@bogon conf]# /usr/sbin/useradd -g ngroup nuser
配置nginx.conf ,将/usr/local/webserver/nginx/conf/nginx.conf替换为以下内容
[root@bogon conf]# cat /usr/local/webserver/nginx/conf/nginx.conf
user nuser ngroup;
worker_processes 4;
error_log /usr/local/webserver/nginx/logs/nginx_error.log;
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
fastcgi_intercept_errors on;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
upstream framework {
sticky;
server 192.168.0.125:8080;
#server 192.168.0.126:8080;
#server 192.168.0.127:8080;
}
upstream analysis {
sticky name=anlysis_route path=/analysis;
server 192.168.0.125:8106;
server 192.168.0.126:8106;
server 192.168.0.127:8106;
}
upstream emgapp {
sticky name=emgapp_route path=/emg-app;
server 192.168.0.126:8088;
server 192.168.0.125:8088;
server 192.168.0.127:8088;
}
server
{
listen 80;
server_name 192.168.0.125;
index index.html index.htm index.php index.jsp;
error_page 500 502 503 504 = /50x.html;
root /usr/local/webserver/nginx/html;
location /analysis/ {
proxy_pass http://analysis;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /emg-app/ {
proxy_pass http://emgapp;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
proxy_pass http://framework;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
检查配置文件ngnix.conf的正确性命令:
[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx -t
网友评论