linux 简易安装教程:
安装make
yumy -y install gcc automake autoconf libtool make
安装gcc
yum install gcc gcc-c++
安装相关依赖
yum -y install pcre-devel openssl openssl-devel zlib-devel
安装nginx
wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.4.2
./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/opt/app/openet/oetal1/chenhe/pcre-8.37 \
--with-zlib=/opt/app/openet/oetal1/chenhe/zlib-1.2.8 \
--with-openssl=/opt/app/openet/oetal1/chenhe/openssl-1.0.1t
make
make instal
配置文件:
结构
#开始
event{
}
http{
server{
}
server{
}
}
#结束
1.user user group nginx Worker进程的用户个组
2.worker_processes 4 进程数
3.worker_rlimit_nofile 52100 文件描述符数量
events
{
4. worker_connections 52100 允许的连接数
}
http
{
5.client_max_body_size 8m 上传文件大小限制
6.gzip on 开启压缩
}
1.目录控制中自动列出目录.
location / {
autoindex on;
}
2. 控制页面缓存时间
location / {
expires 30d;
}
3. 负载均衡、容灾配置
upstream test_pool{
server localhost:8080 weight=1 max_fails=2 fail_timeout=5s;
server localhost:8082 weight=1 max_fails=2 fail_timeout=5s;
}
server {
listen 8000;
server_name localhost;
location / {
proxy_next_upstream http_404 http_500 timeout error invalid_header;
proxy_pass http://test_pool;
}
}
4.设置真实地址
proxy_set_header Host $host;
proxy_set_header X-Forwarded_For $remote_addr;
5.同一个ip落到同一个server
upstream test_pool{
ip_hash;
server localhost:8080 max_fails=2 fail_timeout=5s;
server localhost:8082 max_fails=2 fail_timeout=5s;
}
摘除某一个
upstream test_pool{
ip_hash;
server localhost:8080 max_fails=2 fail_timeout=5s down;
server localhost:8082 max_fails=2 fail_timeout=5s;
}
6.日志配置
http{
#定义格式
log_format combined1 'log:-remote_addr:$remote_addr - remote_user:$remote_user time_local:[$time_local] request:"$request" '
'status:$status body_bytes_sent:$body_bytes_sent "http_referer:$http_referer" '
'"http_user_agent:$http_user_agent" http_x_forwarded_for:"$http_x_forwarded_for"';
}
server{
#申明位置和格式
access_log logs/index.log combined1;
}