资源描述
开发环境代理服务器安装和配置1环境安装11条件1. 操作系统:centos 5.4 64位(或者更高的版本)。2. ssh连接工具:putty。3. 文件传输工具:winscp1.2服务器软件l. nginx 1.4.11)把nginx安装包nginx-141.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-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_gzip_static_module-with-http_stub_status_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 make make install/usr/local/nginx/sbin/nginx1.4注意事项1. 安装的服务器必须是可以出公网,否则依赖包无法安装2. 安装完后加入开机启动3. 启动命令:/usr/local/nginx/sbin/nginx4. 重启命令:killall -9 nginx & /usr/local/nginx/sbin/nginx2环境配置1. 把”代理服务器配置”文件夹下面的conf上传到代理服务器/usr/local/nginx覆盖conf文件夹2. 重启 nginx2.2 一般配置解释配置文 件/usr/local/nginx/conf/nginx.confuser 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;eventsuse epoll;worker_connections 65535;httpincludemime.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_timeout 60;tcp_nodelay on;client body buffer size 512k;proxy_connect_timeout 5; proxy_read_timeout60;proxy_send_timeout5;proxy_buffer_size16k;proxy_buffers4 64k;proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k;gzip on;gzip_minength 1k; gzip_buffers 4 16k;gzip_http_version 1.1;gzip_compevel 2;gzip_typestext/plain application/x-javascript text/css application/xml;gzip_vary on;keys_zone=cache_one:2000m#注:proxy_temp_path和proxy_cache_path指定的路径必须在同一分区 proxy_temp_path /htdocs/proxy_temp_dir;proxy_cache_path /htdocs/proxy_cache_dir levels=1:2 inactive=1d max_size=30g;upstream backend_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_server #这里填写要代理的IP,每个域名单独编写一个upstream,如果后端有多台多负载均衡,可以 配置多个IPserver192.168.1.46:80 weight=1 max_fails=2 fail_timeout=30s;server192.168.1.52:80 weight=1 max_fails=2 fail_timeout=30s;#/serverlisten80;server_name localhost;index index.html index.htm;return 403;access_log off;Serverlisten80;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;expires1d;access_log off;配置中(重要的都进行了注释)upstream backend_server #这里填写要代理的IP,每个域名单独编写一个upstream,如果后端有多台多负载均衡,可以 配置多个IPserver 192.168.1.43:80 weight=1 max_fails=2 fail_timeout=30s;server #一个server表示一个域名的完整配置,每个域名最好应该单独配置一个serverlisten80; #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 的名字 expires1d;access_log off;2.3注意事项1.每次重新配置或者修改配置的时候请重启nginx,否则配置无法生效.
展开阅读全文