[audio:http://media.jybb.me/music/%E6%9E%97%E4%BF%8A%E6%9D%B0%20-%20%E5%8D%81%E7%A7%92%E7%9A%84%E5%86%B2%E5%8A%A8.mp3|autostart=yes]
之前写过给Directadmin上Varnish前端,现在折腾下nginX前端- - 本方法只适用与单ip,全部请求转发到apache。
2013-4-20 Debian亲测可用。
1.安装nginx
CentOS:
1 2 3 4 5 6 7 8 9 |
vi /etc/yum.repos.d/nginx.repo #####添加以下 [nginx] name=nginx repo baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/ gpgcheck=0 enabled=1 ##### yum install nginx |
Debian:
1 2 3 4 5 |
echo "deb http://packages.dotdeb.org squeeze all" >>/etc/apt/sources.list echo "deb-src http://packages.dotdeb.org squeeze all">/etc/apt/sources.list wget http://www.dotdeb.org/dotdeb.gpg cat dotdeb.gpg | apt-key add - apt-get install nginx-full -y |
2. 修改/etc/nginx/nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
user www-data; 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; } } } |
3. 修改apache端口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
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 |
4. 禁止外网ip访问
1 2 3 |
iptables -I INPUT -p TCP --dport 800 -j DROP iptables -I INPUT -s 1.2.3.4 -p TCP --dport 800 -j ACCEPT #1.2.3.4改为外网ip |
5. 重启
1 2 |
service apache restart /etc/init.d/nginx start |
如无特殊情况,此时应该是成功了。。。
很好
这样应该能节约内存吧
The requested URL returned error: 404 Not Found
写的很详细。
内容好丰富的
好长的代码