1.1.1.1 安装nginx
如果使用了F5,则无需安装Nginx
1.1.1.1.1 安装Nginx命令及步骤(Linux系统下安装)
依赖包安装顺序依次为:openssl、zlib、pcre, 然后安装Nginx包.
第一步: 下载安装所需包
1、openssl-1.0.1c.tar.gz
2、zlib-1.2.8.tar.gz
3、pcre-8.1.0.tar.gz
4、nginx-1.2.8.tar.gz
5、nginx-goodies-nginx-sticky-module-ng-f2adff04b8e3.tar.gz
第二步:依次安装
openssl-1.0.1c.tar.gz,nginx-goodies-nginx-sticky-module-ng-f2adff04b8e3.tar.gz,zlib-1.2.8.tar.gz , pcre-8.1.0.tar.gz, ,nginx-1.2.8.tar.gz
进入到/usr/local/目录下,依次操作:
1.解压openssl-1.0.1i.tar.gz
[[email protected] local]# tar -zxvf openssl-1.0.1c.tar.gz
2.解压nginx-goodies-nginx-sticky-module-ng-f2adff04b8e3.tar.gz
[[email protected] local]# tar -zxvf nginx-goodies-nginx-sticky-module-ng-f2adff04b8e3.tar.gz
3.解压zlib-1.2.8.tar.gz
[[email protected] local]# tar -zxvf zlib-1.2.8.tar.gz
[[email protected] local]# cd zlib-1.2.8
4.解压pcre-8.1.0.tar.gz
[[email protected] local]# tar -zxvf pcre-8.1.0.tar.gz
[[email protected] local]# cd pcre-8.1.0
5.解压 nginx-1.2.8.tar.gz
[[email protected] local]# tar -zxvf nginx-1.2.8.tar.gz
[[email protected] local]# cd nginx-1.2.8
[[email protected] nginx-1.2.8]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-openssl=/usr/local/openssl-1.0.1c --with-pcre=/usr/local/pcre-8.10 --with-zlib=/usr/local/zlib-1.2.8 --add-module=/usr/local/nginx-goodies-nginx-sticky-module-ng-f2adff04b8e3
[[email protected] nginx-1.2.8]# make
[[email protected] nginx-1.2.8]# make install
说明:红色字体标示安装nginx的位置。
至此Nginx的安装完成!
第三步:检测是否安装成功
[[email protected] nginx-1.7.2]# cd /usr/local/nginx/sbin
[[email protected] sbin]# ./nginx -t
出现如下所示提示,表示安装成功
- Nginx安装成功提示
启动nginx
[[email protected] sbin]# ./nginx
停止nginx
[[email protected] sbin]# ./nginx –s quit
1.1.1.1 nginx配置参考
在安装的Nginx目录下找到nginx.conf (/usr/local/nginx/conf)
修改如下配置:红色为修改
#user root;
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;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#limit_zone crawler $binary_remote_addr 10m;
# log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
# ‘$status $body_bytes_sent "$http_referer" ‘
# ‘"$http_user_agent" "$http_x_forwarded_for"‘;
sendfile on;
keepalive_timeout 30;
#Nginx后台打印日志配置:
log_format main ‘ $remote_user [$time_local] $http_x_Forwarded_for $remote_addr $request ‘
‘$http_x_forwarded_for ‘
‘$upstream_addr ‘
‘ups_resp_time: $upstream_response_time ‘
‘request_time: $request_time‘;
access_log logs/access.log main;
tcp_nopush on;
#keepalive_timeout 0;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
fastcgi_intercept_errors on;
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;
#Nginx 负载均衡配置 IP为两台服务器的IP,端口是Tomcat中配置的端口
#pasm的负载均衡,pasm的IP与端口
upstream pasm4{
#ip_hash;#当采用session粘贴的时候,则需要打开此配置
#sticky;#用sticky可实现session粘贴,ip_hash和sticky只能开启一个
server 192.168.106.46:58045;
server 192.168.106.63:58045;
}
#ucas的负载均衡,ucas的IP与端口
upstream ucas4{
#ip_hash; #当采用session粘贴的时候,则需要打开此配置
#sticky; #用sticky可实现session粘贴,ip_hash和sticky只能开启一个
server 192.168.106.46:58045;
server 192.168.106.63:58045;
}
#虚拟主机
server {
# Nginx的代理端口,默认80端口,可根据实际情况修改
listen 8046;
#Nginx所在的IP
server_name 192.168.106.21;
#charset utf-8;
# access_log logs/host.access.log main;
location /pasm {
proxy_redirect off;
#注意:nginx默认端口为80,在上面我们修改8046,所以些处修改端口
#可根据实际情况修改
proxy_set_header Host $host:8046;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://pasm4;
root html;
index index.html index.htm;
}
location /ucas {
proxy_redirect off;
#保留用户真实信息
proxy_set_header Host $host:8046;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://ucas4;
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
到此Nginx配置介绍完毕。
1.1.1.2 启动nginx
<[email protected]~>#cd /usr/local/nginx/sbin
<[email protected]~># ./nginx
启动不报错,表示启动成功
1.1.1.3 停止(杀死)nginx进程
<[email protected] sbin># ps –ef | grep nginx
<[email protected] sbin># kill –QUIT 进程号
1.1.1.4 重启Nginx
<[email protected] sbin># /usr/local/nginx/sbin/nginx -s reload
查看Nginx日志
<[email protected] logs># tail –f access.log