您的位置:首页 > 运维架构 > 反向代理

tengine配置实战

2014-05-24 00:00 411 查看
摘要: tengine配置实战

如下配置不够完善,慢慢优化中,请不要在生产上使用

环境

CentOS 6.5,Digitalocean Cloud(邀请

下载安装

1,点击这里进入下载页面

2,安装依赖

yum -y install  pcre-devel
yum -y install make gcc gcc-c++ ncurses-devel make zlib zlib-devel
yum -y install    openssl openssl--devel
#devel的安装不上
#到这里下载http://mirror.centos.org/centos/6.5/updates/x86_64/Packages/
wget  http://mirror.centos.org/centos/6.5/updates/x86_64/Packages/openssl-devel-1.0.1e-16.el6_5.7.x86_64.rpm #rpm -ivh openssl-devel-1.0.1e-16.el6_5.7.x86_64.rpm
#安装时缺少krb5-devel,需要安装krb5
yum -y install krb5-devel
#然后在执行rpm命令就可以安装上了
rpm -ivh openssl-devel-1.0.1e-16.el6_5.7.x86_64.rpm


3,编译安装

./configure  --prefix=/opt/nginx
make
sudo make install


4,开机自启动

vi /etc/init.d/nginx


#输入如下内容

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /opt/nginx/logs/nginx.pid
# config: /opt/nginx/conf/nginx.conf
nginxd=/opt/nginx/sbin/nginx
nginx_config=/opt/nginx/conf/nginx.conf
nginx_pid=/opt/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx $nginx_pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL


给该文件授权

chmod a+x /etc/init.d/nginx


然后再测试下试试



配置实战

nginx.conf

user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  error;

pid        logs/nginx.pid;

worker_rlimit_nofile 65535;

events {
worker_connections  1024;
}

# load modules compiled as Dynamic Shared Object (DSO)
#
#dso {
#    load ngx_http_fastcgi_module.so;
#    load ngx_http_rewrite_module.so;
#}

http {

limit_req_zone $binary_remote_addr zone=ipLimit:10m rate=5r/s;
limit_conn_zone $binary_remote_addr zone=addrLimit:10m;

include       mime.types;
default_type  application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

include  gzip.conf;

server {
listen       80;
server_name  localhost;

#charset koi8-r;

access_log  logs/host.access.log  main;

location ~ .*\.(gif|png|css|js|icon)$ {
proxy_set_header Host $http_host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location ~* .*\.(jpeg|jpg|JPG)$ {
proxy_set_header Host $http_host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#    image_filter resize 480 -;
#    image_filter_jpeg_quality 50;
#    image_filter_sharpen 10;
#    image_filter_buffer 4M;
}

location / {
limit_req zone=ipLimitburst=5;
root   html;
index  index.html index.htm;
}

error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}

}

}


gzip.conf

gzip on;
gzip_min_length   1k;
gzip_comp_level   3;
gzip_buffers      16 64k;
gzip_types text/plain application/x-javascript text/css text/javascript;

gzip_http_version 1.1;
gzip_proxied      any;
gzip_vary         on;
gzip_disable "MSIE [1-6].";


实战详解

什么是反向代理

计算机网络中,反向代理代理服务器的一种。它根据客户端的请求,从后端的服务器上获取资源,然后再将这些资源返回给客户端。[1]前向代理不同,前向代理作为一个媒介将互联网上获取的资源返回给相关联的客户端,而反向代理是在服务器端作为代理使用,而不是客户端。

主要有什么功能

反向代理的主要作用为:

加密和SSL加速

负载均衡

缓存静态内容

压缩

减速上传

安全

外网发布





未完待续......

参考

tengine官方文档

维基百科反向代理
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  tengine nginx 反向代理