Ezra 2012-11-10
代码如下:
/sbin/sysctl -p
代码如下:
echo -ne "alias net-pf-10 off\noptions ipv6 disable=1" >>/etc/modprobe.conf /sbin/chkconfig --level 35 ip6tables off
代码如下:
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
代码如下:
sed -i 's#SYNC_HWCLOCK=no#SYNC_HWCLOCK=yes#' /etc/sysconfig/ntpd
代码如下:
echo "0 6 * * * /usr/sbin/ntpdate 192.168.0.172;/sbin/hwclock -w; >/dev/null 2>&1" >>/var/spool/cron/root service crond restart
代码如下:
sed -i 's/id:5:initdefault:/id:3:initdefault:/g' /etc/inittab
代码如下:
sed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/" /etc/inittab
代码如下:
groupadd www useradd -g www www -s /bin/false
代码如下:
mkdir -p /data/html/www mkdir -p /data/proxy_temp_dir mkdir -p /data/proxy_cache_path mkdir -p /data/logs chown -R www:www /data/proxy_cache_path chown -R www:www /data/proxy_temp_dir chown -R www:www /data/html/ chown -R www:www /data/logs
代码如下:
yum -y install openssl-devel kernel-devel
代码如下:
tar zxvf pcre-8.31.tar.gz cd pcre-8.31 ./configure --prefix=/usr/local/pcre make make install
代码如下:
tar zxvf ngx_cache_purge-1.6.tar.gz tar zxvf nginx-1.3.3.tar.gz tar zxvf nginx_upstream_check_module.tar.gz cd nginx-1.3.3 patch -p1 < /root/nginx_keepalived_install/nginx_upstream_check_module/check_1.2.2+.patch ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_realip_module --with-http_gzip_static_module --with-openssl=/usr/ --with-pcre=/root/nginx_keepalived_install/pcre-8.31 --add-module=/root/nginx_keepalived_install/ngx_cache_purge-1.6 --add-module=/root/nginx_keepalived_install/nginx_upstream_check_module make make install cp /root/nginx_keepalived_install/cut_nginx_log.sh /usr/local/nginx/sbin/ chmod +x /usr/local/nginx/sbin/cut_nginx_log.sh echo -ne "00 00 * * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh" >>/var/spool/cron/root service crond restart chown -R www:www /usr/local/nginx/ cp /root/nginx_keepalived_install/nginx /etc/rc.d/init.d/ chmod +x /etc/rc.d/init.d/nginx chkconfig nginx on
代码如下:
user www www; worker_processes 8; worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000; worker_rlimit_nofile 204800; error_log /data/logs/error.log; pid logs/nginx.pid; events { worker_connections 240800; use epoll; } http { include nginx_load_balance.conf; #include proxy.conf; include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; #log_format access '$remote_addr - $remote_user [$time_local] "$request" ' #'$status $body_bytes_sent "$http_referer" ' #'"$http_user_agent" $http_x_forwarded_for'; #access_log /data/logs/access.log access; sendfile on; tcp_nopush on; tcp_nodelay on; server_tokens off; keepalive_timeout 60; client_header_buffer_size 4k; #large_client_header_buffers 4 32k; client_max_body_size 10m; client_header_timeout 120s; client_body_timeout 120s; send_timeout 120s; gzip off; gzip_min_length 1k; gzip_buffers 4 16k; output_buffers 1 512k; postpone_output 1460; #gzip_http_version 1.1; gzip_comp_level 4; gzip_types text/plain text/css text/javascript text/xml application/x-javascript application/xml application/xml+rss; gzip_vary on; server { listen 80; server_name localhost; location / { rewrite ^ http://www.test.com$request_uri?; #root /data/html/www; #index index.html index.htm; } error_page 404 /data/html/www/404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location /status { stub_status on; access_log off; } location /nstatus { check_status; access_log off; #allow SOME.IP.ADD.RESS; #deny all; } } include vhost/*.conf; }
代码如下:
upstream dx { ip_hash; server 192.168.0.11:80; server 192.168.0.12:80; server 192.168.0.13:80; server 192.168.0.14:80; server 192.168.0.15:80; check interval=3000 rise=2 fall=8 timeout=3000 type=http; check_http_send "GET / HTTP/1.0\r\n\r\n"; check_http_expect_alive http_2xx http_3xx http_4xx; #server 192.168.0.30:80; backup; } upstream lt { ip_hash; server 192.168.1.11:80; server 192.168.1.12:80; server 192.168.1.13:80; server 192.168.1.14:80; server 192.168.1.15:80; check interval=3000 rise=2 fall=8 timeout=3000 type=http; check_http_send "GET / HTTP/1.0\r\n\r\n"; check_http_expect_alive http_2xx http_3xx http_4xx; #server 192.168.1.30:80; backup; }
代码如下:
proxy_temp_path /data/proxy_temp_dir; #指定临时文件目录 proxy_cache_path /data/proxy_cache_path levels=1:2 keys_zone=cache_one:2000m inactive=1d max_size=1g; client_body_buffer_size 512k; #增加缓冲区代理缓冲客户端请求的最大字节数 proxy_connect_timeout 60; #增加连接后端服务器超时时间 proxy_read_timeout 60; #增加后端服务器响应请求超时时间 proxy_send_timeout 60; #增加后端服务器发送数据超时时间 proxy_buffer_size 32k; #增加代理请求缓存区大小 proxy_buffers 4 64k; #增加 proxy_busy_buffers_size 128k; #增加系统繁忙时可申请的proxy_buffers大小 proxy_temp_file_write_size 128k; #增加proxy缓存临时文件的大小 proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; #增加故障转移,如果后端的服务器返回502、504、执行超时等错误,自动将请求转发到upstream负载均衡池中的另一台服务器,实现故障转移。 proxy_cache cache_one; #增加使用web缓存区cache_one
代码如下:
server { listen 192.168.0.1; server_name xxx.com; access_log /data/logs/dx.log dx; location / { proxy_next_upstream http_502 http_504 error timeout invalid_header; # proxy_cache cache_one; # proxy_cache_valid 200 304 12h; # proxy_cache_key $host$uri$is_args$args; proxy_set_header Host $http_host; #proxy_set_header X-Real-IP $remote_addr; # proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_headers_hash_max_size 51200; proxy_headers_hash_bucket_size 6400; proxy_pass http://dx; #if ($request_uri ~* "^/upload/") { #add_header Cache-Control 'max-age=86400'; #} location ~* \.(gif|jpg|jpeg|png|flv|swf|ico)$ { proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://dx; add_header Cache-Control 'max-age=86400'; } location ~* \.(js)$ { proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://dx; add_header Cache-Control 'max-age=600'; } #expires -1; add_header Cache-Control 'no-store, no-cache, must-revalidate'; add_header Pragma no-cache; } location ~ /purge(/.*) { allow 127.0.0.1; allow 192.168.0.0/16; deny all; #proxy_cache_purge cache_one $host$1$is_args$args; } location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$ { proxy_set_header Host $http_host; #proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://dx; } } server { listen 192.168.1.1; server_name xxxx.com; access_log /data/logs/lt.log lt; location / { proxy_next_upstream http_502 http_504 error timeout invalid_header; #proxy_cache cache_one; #proxy_cache_valid 200 304 12h; #proxy_cache_key $host$uri$is_args$args; proxy_set_header Host $http_host; #proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_headers_hash_max_size 51200; proxy_headers_hash_bucket_size 6400; proxy_pass http://lt; #if ($request_uri ~* "^/upload/") { #add_header Cache-Control 'max-age=86400'; #} location ~* \.(gif|jpg|jpeg|png|flv|swf|ico)$ { proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://lt; add_header Cache-Control 'max-age=86400'; } location ~* \.(js)$ { proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://lt; add_header Cache-Control 'max-age=600'; } #expires -1; add_header Cache-Control 'no-store, no-cache, must-revalidate'; add_header Pragma no-cache; } location ~ /purge(/.*) { allow 127.0.0.1; allow 192.168.0.0/16; deny all; #proxy_cache_purge cache_one $host$1$is_args$args; } location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$ { proxy_set_header Host $http_host; #proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://lt; } }
某些公司会墙特定网站,如果你有一个可访问的域名和服务器,就可以通过nginx反向代理来来解决这些问题。比如现在我们用mirror.example.com镜像www.baidu.com,以下是详细操作。