- 设定负载均衡的服务器列表
upstream portals {
server 172.16.68.134:8082 max_fails=2 fail_timeout=30s;
server 172.16.68.135:8082 max_fails=2 fail_timeout=30s;
server 172.16.68.136:8082 max_fails=2 fail_timeout=30s;
server 172.16.68.137:8082 max_fails=2 fail_timeout=30s;
} - http://10.248.6.45:8080;
# }">设定查看Nginx状态的地址
location ~* ^/NginxStatus/ {
stub_status on;
access_log off;
allow 10.1.252.126;
allow 10.248.6.49;
allow 127.0.0.1;
deny all;
}
# error_page 405 =200 @405;
# location @405
# {
# proxy_pass http://10.248.6.45:8080;
# }
- 安装pcre-8.12.tar.gz
直接执行以下命令: (到目录下)
# tar -zxvf pcre-8.21.tar.gz
# cd pcre-8.21
# ./configure
# make
# make install
2. 安装zlib-1.2.8.tar.gz
wget http://zlib.net/zlib-1.2.8.tar.gz
# tar -xf zlib-1.2.8.tar.gz
# cd zlib-1.2.8
# ./configure
# make
# make install
3. 安装openssl-1.0.1c.tar.gz
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
# tar -zxvf openssl-1.0.1c.tar.gz
# cd openssl-1.0.1c
# ./config
# make
# make install
4. 安装依赖环境
yum -y install gcc gcc-c++ autoconf automake
yum -y install zlib-devel openssl openssl-devel pcre-devel
安装不成功则需要手动一个一个进行安装
5. 安装nginx-1.2.8.tar.gz
wget http://nginx.org/download/nginx-1.2.8.tar.gz
# tar -zxvf nginx-1.2.8.tar.gz
# cd nginx-1.2.8
# ./configure —prefix=/usr/local/nginx
也可以这样写:
# make
# make install
6. 检测是否安装成功
# cd 目录/nginx/sbin
# ./nginx -t
如果出现以下提示,表示安装成功:
7. 启动Nginx
# ./nginx
重启Nginx
/usr/local/nginx/sbin/nginx -s reload
检查修改配置文件是否正确:
nginx -t
8. 查看端口号:
# netstat -ntlp
出现如下样式即可:
9. 打开浏览器访问设置IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。(默认端口为80)
#全局错误日志及PID文件
pid /var/run/nginx.pid;
error_log /var/log/nginx/error.log;
events {
#epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能
use epoll;
#单个后台worker process进程的最大并发链接数
worker_connections 10240;
}
#设定http服务器,利用它的反向代理功能提供负载均衡支持
http {
include mime.types;
default_type application/octet-stream;
error_page 400 403 500 502 503 504 /50x.html;
index index.html index.shtml
autoindex off;
fastcgi_intercept_errors on;
sendfile on;
# These are good default values.<br /> tcp_nopush on;<br /> tcp_nodelay off;
# output compression saves bandwidth<br /> gzip off;<br /> #gzip_static on;<br /> #gzip_min_length 1k;<br /> gzip_http_version 1.0;<br /> gzip_comp_level 2;<br /> gzip_buffers 4 16k;<br /> gzip_proxied any;<br /> gzip_disable "MSIE [1-6]\.";<br /> gzip_types text/plain text/html text/css application/x-javascript application/xml application/xml+rss text/javascript;<br /> #gzip_vary on;
server_name_in_redirect off;
设定负载均衡的服务器列表
upstream portals {
server 172.16.68.134:8082 max_fails=2 fail_timeout=30s;
server 172.16.68.135:8082 max_fails=2 fail_timeout=30s;
server 172.16.68.136:8082 max_fails=2 fail_timeout=30s;
server 172.16.68.137:8082 max_fails=2 fail_timeout=30s;
}
#upstream overflow {<br /> # server 10.248.6.34:8090 max_fails=2 fail_timeout=30s; <br /> # server 10.248.6.45:8080 max_fails=2 fail_timeout=30s; <br /> #}
server {<br /> #侦听8080端口<br /> listen 8080;<br /> server_name 127.0.0.1;
#403、404页面重定向地址<br /> error_page 403 = http://www.e100.cn/ebiz/other/217/403.html;<br /> error_page 404 = http://www.e100.cn/ebiz/other/218/404.html;<br /> proxy_connect_timeout 90;<br /> proxy_send_timeout 180;<br /> proxy_read_timeout 180;
proxy_buffer_size 64k;<br /> proxy_buffers 4 128k;<br /> proxy_busy_buffers_size 128k;
client_header_buffer_size 16k;<br /> large_client_header_buffers 4 64k;
#proxy_send_timeout 3m;<br /> #proxy_read_timeout 3m;<br /> #proxy_buffer_size 4k;<br /> #proxy_buffers 4 32k;
proxy_set_header Host $http_host;<br /> proxy_max_temp_file_size 0;<br /> #proxy_hide_header Set-Cookie;<br /> <br /> # if ($host != 'www.e100.cn' ) {<br /> # rewrite ^/(.*)$ http://www.e100.cn/$1 permanent;<br /> # }
location / {<br /> deny all;<br /> }
location ~ ^/resource/res/img/blue/space.gif {<br /> proxy_pass http://tecopera;<br /> }
location = / {<br /> rewrite ^(.*)$ /ebiz/event/517.html last;<br /> }
location = /ebiz/event/517.html {<br /> add_header Vary Accept-Encoding;<br /> root /data/web/html;<br /> expires 10m;<br /> }
location = /check.html {<br /> root /usr/local/nginx/html/;<br /> access_log off;<br /> }
location = /50x.html {<br /> root /usr/local/nginx/html/;<br /> expires 1m;<br /> access_log off;<br /> }
location = /index.html {<br /> add_header Vary Accept-Encoding;<br />#定义服务器的默认网站根目录位置<br /> root /data/web/html/ebiz;<br /> expires 10m;<br /> }<br />#定义反向代理访问名称<br /> location ~ ^/ecps-portal/* {<br /> # expires 10m;<br />#重定向集群名称<br /> proxy_pass http://portals;<br /> #proxy_pass http://172.16.68.134:8082;<br /> }
location ~ ^/fetionLogin/* {<br /> # expires 10m;<br /> proxy_pass http://portals;<br /> #proxy_pass http://172.16.68.134:8082;<br /> }
#location ~ ^/business/* { <br /> # # expires 10m; <br /> # proxy_pass http://172.16.68.132:8088; <br /> # #proxy_pass http://172.16.68.134:8082; <br /> #}
location ~ ^/rsmanager/* {<br /> expires 10m;<br /> root /data/web/;<br /> #proxy_pass http://rsm;<br /> }<br />#定义nginx处理的页面后缀<br /> location ~* (.*)\.(jpg|gif|htm|html|png|js|css)$ {<br /> root /data/web/html/;<br />#页面缓存时间为10分钟<br /> expires 10m;<br /> }
设定查看Nginx状态的地址
location ~* ^/NginxStatus/ {
stub_status on;
access_log off;
allow 10.1.252.126;
allow 10.248.6.49;
allow 127.0.0.1;
deny all;
}
# error_page 405 =200 @405;
# location @405
# {
# proxy_pass http://10.248.6.45:8080;
# }
access_log /data/logs/nginx/access.log combined;<br /> error_log /data/logs/nginx/error.log;<br /> }<br /> server {<br /> listen 8082;
server_name _;<br /> location = /check.html {<br /> root /usr/local/nginx/html/;<br /> access_log off;<br /> }<br /> <br /> }<br /> server {<br /> listen 8088;<br /> server_name _;<br /> location ~ ^/* {<br /> root /data/web/b2bhtml/;<br /> access_log off;<br /> } <br /> }<br /> server {<br /> listen 9082;<br /> server_name _;
# location ~ ^/resource/* {<br /> # expires 10m;<br /> # root /data/web/html/;<br /> # }
location / {<br /> root /data/web/html/sysMaintain/;<br /> if (!-f $request_filename) {<br /> rewrite ^/(.*)$ /sysMaintain.html last;<br /> }<br /> }<br /> }
}