1、zlib
wget http://www.zlib.net/fossils/zlib-1.2.8.tar.gz
2、openssl
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
3、pcre
wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz
注解:以上编译统一使用
tar -xf *.gz
cd 文件目录
./configure
make && makeinstall
4、简易版安装
yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel
5、
6、启动、关闭、重启
进入nginx的bin目录
./nginx
./nginx -s stop
./nginx -s reload
7、反向代理
location / { #设置主机头和客户端真实地址,以便服务器获取客户端真实IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#禁用缓存 proxy_buffering off;
#设置反向代理的地址
proxy_pass http://192.168.1.1;
}
8、负载均衡
upstream test{ #ip_hash;
server 192.168.1.251;
server 192.168.1.252;
server 192.168.1.247;
}
server {
listen 80;
server_name helloword;
location / {
#反向代理的地址
proxy_pass http://test;
}
}
9、动静分离
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on; keepalive_timeout 65;
upstream test {
#ip_hash;
server 192.168.1.251;
server 192.168.1.252;
server 192.168.1.247;
}
server {
listen 80;
server_name 2;
#配置Nginx动静分离,定义的静态页面直接从Nginx发布目录读取。
location ~ .*.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /usr/local/nginx/html/myloan;
#expires定义用户浏览器缓存的时间为7天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
expires 7d;
} #所有jsp、do的动态请求都交给后面的tomcat处理
location ~ (.jsp)|(.do)$ {
#tomcat地址 proxy_pass http://test;
proxy_redirect off;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
}
读到这里的朋友,如果您感觉对您有帮助,请帮助分享一下。谢谢。