1、开发环境代理服务器安装和配置1 环境安装1.1 条件1 操作系统:centos 5.4 64 位( 或者更高的版本)。2 ssh 连接工具:putty 。3 文件传输工具:winscp1.2 服务器软件1.nginx 1.4.11.3 安装步骤1)把 nginx 安装包 nginx-1.4.1.tar.gz、pcre-8.32.tar.gz 上传到指定的安装目录,并同时对两个文件进行解压2)安装脚本yum -y install gcc gcc-c+ openssl openssl-develcd nginx-1.4.1./configure -prefix=/usr/local/nginx -
2、sbin-path=/usr/local/nginx/sbin/nginx -conf-path=/usr/local/nginx/conf/nginx.conf -error-log-path=/usr/local/nginx/log/error.log -http-log-path=/usr/local/nginx/log/access.log -pid-path=/usr/local/nginx/run/nginx.pid -user=www -group=www -with-http_ssl_module -with-http_flv_module -with-http_stub_st
3、atus_module -with-http_gzip_static_module -http-client-body-temp-path=/usr/local/nginx/tmp/client -http-proxy-temp-path=/usr/local/nginx/tmp/proxy/ -http-fastcgi-temp-path=/usr/local/nginx/tmp/fcgi/ -add-module=./ngx_cache_purge-2.1 -with-pcre=./ pcre-8.32makemake install/usr/local/nginx/sbin/nginx1
4、.4 注意事项1. 安装的服务器必须是可以出公网,否则依赖包无法安装2. 安装完后加入开机启动3. 启动命令: /usr/local/nginx/sbin/nginx 4. 重启命令: killall -9 nginx worker_processes 8;error_log /usr/local/nginx/logs/nginx_error.log crit;pid /usr/local/nginx/nginx.pid;#Specifies the value for maximum file descriptors that can be opened by this process.wo
5、rker_rlimit_nofile 65535;eventsuse epoll;worker_connections 65535;httpinclude mime.types;default_type application/octet-stream;charset utf-8;server_names_hash_bucket_size 128;client_header_buffer_size 32k;large_client_header_buffers 4 32k;client_max_body_size 300m;sendfile on;tcp_nopush on;keepalive
6、_timeout 60;tcp_nodelay on;client_body_buffer_size 512k;proxy_connect_timeout 5;proxy_read_timeout 60;proxy_send_timeout 5;proxy_buffer_size 16k;proxy_buffers 4 64k;proxy_busy_buffers_size 128k;proxy_temp_file_write_size 128k;gzip on;gzip_min_length 1k;gzip_buffers 4 16k;gzip_http_version 1.1;gzip_c
7、omp_level 2;gzip_types text/plain application/x-javascript text/css application/xml;gzip_vary on;#注:proxy_temp_path 和 proxy_cache_path 指定的路径必须在同一分区proxy_temp_path /htdocs/proxy_temp_dir;proxy_cache_path /htdocs/proxy_cache_dir levels=1:2 keys_zone=cache_one:2000m inactive=1d max_size=30g;upstream ba
8、ckend_server #这里填写要代理的 IP,每个域名单独编写一个 upstream,如果后端有多台多负载均衡,可以配置多个 IPserver 192.168.1.43:80 weight=1 max_fails=2 fail_timeout=30s;upstream rb_backend_server #这里填写要代理的 IP,每个域名单独编写一个 upstream,如果后端有多台多负载均衡,可以配置多个 IPserver 192.168.1.10:80 weight=1 max_fails=2 fail_timeout=30s;upstream portaltest_backend_
9、server #这里填写要代理的 IP,每个域名单独编写一个 upstream,如果后端有多台多负载均衡,可以配置多个 IPserver 192.168.1.46:80 weight=1 max_fails=2 fail_timeout=30s;server 192.168.1.52:80 weight=1 max_fails=2 fail_timeout=30s;#/serverlisten 80;server_name localhost;index index.html index.htm;return 403;access_log off;Server listen 80;server
10、_name ;index index.html index.htm;location /proxy_next_upstream http_502 http_504 error timeout invalid_header;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $remote_addr;proxy_pass http:/backend_server;expires 1d;access_log off;配置中(重要的都进行了注释 )upstream backend_server #这里填写要代理的 IP,每个域名单
11、独编写一个 upstream,如果后端有多台多负载均衡,可以配置多个 IPserver 192.168.1.43:80 weight=1 max_fails=2 fail_timeout=30s;server #一个 server 表示一个域名的完整配置,每个域名最好应该单独配置一个 serverlisten 80; #server_name ; #要配置的域名index index.html index.htm; #默认页面location /proxy_next_upstream http_502 http_504 error timeout invalid_header;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $remote_addr;proxy_pass http:/backend_server; #upstream 的名字expires 1d;access_log off;2.3 注意事项1.每次重新配置或者修改配置的时候请重启 nginx,否则配置无法生效.