作者:乐韵答题 | 来源:互联网 | 2014-05-28 09:40
Nginx的安装1、安装pcre库unzippcre-8.12.zipcdpcre-8.12./configuremake%makeinstall2、安装nginxuseraddnginxtarxfnginx-0.8.53.tar.gzcdnginx-0.8.53./configure?prefix/home/ngin
Nginx的安装
1、安装pcre库
unzip pcre-8.12.zip
cd pcre-8.12
./configure
make % make install
2、安装
nginx
useradd nginx
tar xf nginx-0.8.53.tar.gz
cd nginx-0.8.53
./configure ?prefix=/home/nginx/nginx
--with-http_stub_status_module --with-http_ssl_module
make & make install
3、注意事项
如果使用非root用户启动,会提示警告,可以将该用户赋予sudo权限。
修改配置文件
cd /home/nginx/nginx/conf
vim nginx.conf
输入如下内容
user nginx nginx;
worker_processes 8;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
worker_rlimit_nofile 51200;
events {
use epoll;
worker_connections 51200;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
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;
#tcp_nopush on;
keepalive_timeout 65;
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;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 64k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-Javascript
text/css application/xml;
gzip_vary on;
client_max_body_size 300m;
client_body_buffer_size 128k;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_buffer_size 16k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
upstream media_pool {
server 10.2.1.117:8080 weight=1 max_fails=2
fail_timeout=30s;
server 10.2.1.118:8080 weight=1 max_fails=2
fail_timeout=30s;
}
以上红色部分为
反向代理池,定义后端被代理的服务器地址及端口。
server {
listen
8085;#代理服务器监听端口
server_name
www.server110.com;#代理服务器的名称可以是域名也可以是IP
#charset koi8-r;
access_log
logs/media.access.log main;#定义日志
location /inteSvr/ { #定义规则,目录
proxy_pass
http://media_pool/inteSvr/; #转发规则
proxy_set_header Host
$host:8085; #跳转头信息
proxy_set_header
X-Forwarded-For $remote_addr;#将真实IP传到后面代理服务器
}
}
以上红色部分为定义转发服务器规则。
}
启动、停止、重启
启动 /home/nginx/nginx/bin/nginx.start
#!/bin/bash
/home/nginx/nginx/sbin/nginx -c
/home/nginx/nginx/conf/nginx.conf
停止
/home/nginx/nginx/bin/nginx.stop
#!/bin/bash
killall nginx
重启
/home/nginx/nginx/bin/nginx.restart
#!/bin/bash
kill -HUP `cat /home/nginx/nginx/logs/nginx.pid`