1、开发环境代理服务器安装和配置 1环境安装 1.1条件 1. 操作系统:centos 5.4 64位(或者更高的版本)。 2. ssh连接工具:putty。 3. 文件传输工具:winscp 1.2服务器软件 1.nginx 1.4.1 1.3安装步骤 1)把nginx安装包 nginx-1.4.1.tar.gz、pcre-8.32.tar.gz上传到指定的安装目录,并同时对两个文件进行解压 2)安装脚本 yum -y install gcc gcc-c++ openssl openssl-devel cd nginx-1.4.1 ./configure --pref
2、ix=/usr/local/nginx --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-h
3、ttp_flv_module --with-http_stub_status_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.32 m
4、ake make install /usr/local/nginx/sbin/nginx 1.4注意事项 1. 安装的服务器必须是可以出公网,否则依赖包无法安装 2. 安装完后加入开机启动 3. 启动命令: /usr/local/nginx/sbin/nginx 4. 重启命令: killall -9 nginx && /usr/local/nginx/sbin/nginx 2环境配置 2.1配置步骤 1.把”代理服务器配置”文件夹下面的conf上传到代理服务器/usr/local/nginx 覆盖conf文件夹 2.重启nginx 2.2一般配置解释 配置文件/
5、usr/local/nginx/conf/nginx.conf user www www; 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. worker_rlimit_nofile 65535; events { use e
6、poll; worker_connections 65535; } http { include 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
7、 on; keepalive_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_writ
8、e_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_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/pr
9、oxy_temp_dir; proxy_cache_path /htdocs/proxy_cache_dir levels=1:2 keys_zone=cache_one:2000m inactive=1d max_size=30g; upstream backend_server { #这里填写要代理的IP,每个域名单独编写一个upstream,如果后端有多台多负载均衡,可以配置多个IP server 192.168.1.43:80 weight=1 max_fails=2 fail_timeout=30s; } upstream r
10、b_backend_server { #这里填写要代理的IP,每个域名单独编写一个upstream,如果后端有多台多负载均衡,可以配置多个IP server 192.168.1.10:80 weight=1 max_fails=2 fail_timeout=30s; } upstream portaltest_backend_server { #这里填写要代理的IP,每个域名单独编写一个upstream,如果后端有多台多负载均衡,可以配置多个IP server 192.168.1.46:80 weight=1 max_fails=2 fail
11、timeout=30s; server 192.168.1.52:80 weight=1 max_fails=2 fail_timeout=30s; } #//// server { listen 80; server_name localhost; index index.html index.htm; return 403; access_log off; } Server { listen 80; server_name ; in
12、dex 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; }
13、 access_log off; } } 配置中(重要的都进行了注释) upstream backend_server { #这里填写要代理的IP,每个域名单独编写一个upstream,如果后端有多台多负载均衡,可以配置多个IP server 192.168.1.43:80 weight=1 max_fails=2 fail_timeout=30s; } server #一个server 表示一个域名的完整配置,每个域名最好应该单独配置一个server { listen 80; # server_name ; #
14、要配置的域名 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,否则配置无法生效.






