下面是少量缓存 反代。配置方法,我运用在da下面。其他环境也适用,
只不要过改apache端口的时候修改对应文件即可
下载nginx安装包:
CentOS5:
wget http://download.efsync.org/Nginx/nginx-release-rhel-5-0.el5.ngx.noarch.rpm
CentOS6:
wget http://download.efsync.org/Nginx/nginx-release-rhel-6-0.el6.ngx.noarch.rpm
安装nginx:
CentOS5:
rpm -ivh nginx-release-rhel-5-0.el5.ngx.noarch.rpm
CentOS6:
rpm -ivh nginx-release-rhel-6-0.el6.ngx.noarch.rpm
安装完成后把nginx升级为最新版1.4
yum install -y nginx
添加一个用户和用户组用来运行nginx
groupadd www
useradd -s /sbin/nologin -g www www
修改nginx配置文件
先删除原配置文件
rm -rf /etc/nginx/nginx.conf
新建一个配置文件
vi /etc/nginx/nginx.conf
写入以下代码:(把里的IP改你的真实IP)
user www;
worker_processes 2; #进程数
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
client_body_buffer_size 512k;
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 20;
proxy_buffer_size 32k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_temp_path /home/cache/temp;
proxy_cache_path /home/cache/path levels=1:2 keys_zone=cache_one:50m inactive=7d max_size=30g;
limit_conn_zone $binary_remote_addr zone=default:3m;
server
{
listen 80;
server_name localhost;
set $no_cache 0;
if ($request_method = POST) {
set $no_cache 1;
}
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9] |wp-postpass|wordpress_no_cache|wordpress_logged_in|uin") {
set $no_cache 1;
}
location /
{
limit_conn default 10; #单ip进程数3
proxy_cache_bypass $no_cache;
proxy_no_cache $no_cache;
proxy_cache cache_one;
proxy_cache_valid 200 304 2s; #各种状态缓存时间
proxy_cache_valid 302 30m;
proxy_cache_valid 301 2d;
proxy_cache_valid 502 20s;
proxy_cache_valid any 10s;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_use_stale invalid_header error timeout http_502 http_503 http_504; #502 503 504使用旧缓存
proxy_pass http://公网ip:800;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
expires 30s;
access_log off;
}
location ~*\.(js|css|gif|png|bmp|jpeg|jpg|swf)$
{
proxy_pass http://公网ip:800;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_cache cache_one;
proxy_cache_valid 200 304 3m;
proxy_cache_key $host$uri$is_args$args;
expires 1d;
}
location ~* wp\-.*\.php|wp\-admin {
limit_conn default 1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_cache_lock on;
proxy_cache cache_one;
proxy_cache_valid any 3m;
proxy_cache_key $host$uri$is_args$args;
proxy_pass http://公网ip:800;
expires 1h;
}
}
}
修改Apache的端口为800
sed -i "s#ips.conf#ips_hack.conf#g" /etc/httpd/conf/extra/httpd-vhosts.conf
cp /etc/httpd/conf/ips.conf /etc/httpd/conf/ips_hack.conf
sed -i "s#:80#:800#g" /etc/httpd/conf/ips_hack.conf
sed -i "s#:80#:800#g" /etc/httpd/conf/extra/httpd-vhosts.conf
sed -i "s#:80#:800#g" /usr/local/directadmin/data/templates/ips_virtual_host.conf
sed -i "s#:|PORT_80|#:800#g" /usr/local/directadmin/data/templates/virtual_host2_sub.conf
sed -i "s#:80#:800#g" /usr/local/directadmin/data/templates/virtual_host2_sub.conf
sed -i "s# |MULTI_IP|##g" /usr/local/directadmin/data/templates/virtual_host2_sub.conf
sed -i "s/CustomLog/#CustomLog/g" /usr/local/directadmin/data/templates/virtual_host2_sub.conf
sed -i "s#:|PORT_80|#:800#g" /usr/local/directadmin/data/templates/virtual_host.conf
sed -i "s#:80#:800#g" /usr/local/directadmin/data/templates/virtual_host.conf
sed -i "s# |MULTI_IP|##g" /usr/local/directadmin/data/templates/virtual_host.conf
sed -i "s/CustomLog/#CustomLog/g" /usr/local/directadmin/data/templates/virtual_host.conf
sed -i "s#:|PORT_80|#:800#g" /usr/local/directadmin/data/templates/virtual_host_sub.conf
sed -i "s#:80#:800#g" /usr/local/directadmin/data/templates/virtual_host_sub.conf
sed -i "s# |MULTI_IP|##g" /usr/local/directadmin/data/templates/virtual_host_sub.conf
sed -i "s/CustomLog/#CustomLog/g" /usr/local/directadmin/data/templates/virtual_host_sub.conf
sed -i "s#:|PORT_80|#:800#g" /usr/local/directadmin/data/templates/redirect_virtual_host.conf
sed -i "s#:80#:800#g" /usr/local/directadmin/data/templates/redirect_virtual_host.conf
sed -i "s# |MULTI_IP|##g" /usr/local/directadmin/data/templates/redirect_virtual_host.conf
sed -i "s#:|PORT_80|#:800#g" /usr/local/directadmin/data/templates/virtual_host2.conf
sed -i "s#:80#:800#g" /usr/local/directadmin/data/templates/virtual_host2.conf
sed -i "s# |MULTI_IP|##g" /usr/local/directadmin/data/templates/virtual_host2.conf
sed -i "s/CustomLog/#CustomLog/g" /usr/local/directadmin/data/templates/virtual_host2.conf
sed -i "s#Port 80#Port 800#g" /usr/local/directadmin/data/templates/httpd.conf
sed -i "s#Listen 80#Listen 800#g" /usr/local/directadmin/data/templates/httpd.conf
sed -i "s#Listen 80#Listen 800#g" /etc/httpd/conf/httpd.conf
sed -i "s#:80#:800#g" /usr/local/directadmin/data/users/*/httpd.conf
重启apache
service httpd restart
重启nginx
/etc/init.d/nginx start
大功告成
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。