Monday, June 9, 2014

Nginx as CDN

user www-data;
worker_processes 4;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    # multi_accept on;
}

http {
        server_names_hash_bucket_size 64;
        include       /etc/nginx/mime.types;

        access_log      /var/log/nginx/access.log;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

#### firstApp and secondApp Caching
    proxy_cache_path    /var/www/cache/firstApp levels=1:2 keys_zone=firstApp_cache:30m max_size=500m inactive=600m;
    # secondApp Caching
    proxy_cache_path    /var/www/cache/secondApp levels=1:2 keys_zone=secondApp_cache:30m max_size=500m inactive=600m;

    proxy_temp_path     /var/www/cache/tmp;
    # secondApp app CDN
    server {
        listen 5002;
        ssl on;
        ssl_certificate /etc/nginx/vmh02-cdn01-p91.myDomain.net.crt;
        ssl_certificate_key /etc/nginx/vmh02-cdn01-p91.myDomain.net.key;

        #listen       443;
        server_name  vmh02-cdn01-p91.myDomain.net;
        location / {
            proxy_pass https://AppUrlforSecondApp.mysecondappURL.net/;  #// this should point to secondApp server secondApp -
            proxy_cache secondApp_cache;
            proxy_cache_valid 200 302 60m;
            proxy_cache_valid 404 1m;
            #root   html;
            #index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
### app CDN
    server {
        listen  5008;
        ssl on;
        ssl_certificate /etc/nginx/vmh02-cdn01-p91.myDomain.net.crt;
        ssl_certificate_key /etc/nginx/vmh02-cdn01-p91.myDomain.net.key;
        server_name  vmh02-cdn01-p91.myDomain.net;
        location / {
            proxy_pass https://secondAppLInk-stage.AppSitelinkHere.net/;  #// this should be the firstApp IP address or LB
            proxy_cache firstApp_cache;
            proxy_cache_valid 200 302 60m;
            proxy_cache_valid 404 1m;
        }
   }
}

Saturday, June 7, 2014

netstat

To display open ports, enter:
netstat --listen
To display open ports and established TCP connections on a Linux host, enter:
netstat -vatn
Run these on the hosts that stop responding.
Additionally, you can use strace to trace system calls and signals. Specify the "-e trace=network" trace the network-related system calls. As an example, you can run the following command to trace the network signals for the ping -c 3 10.0.0.1command and output to a file called "ping.trace".
strace -e trace=network -o ping.trace ping -c 3 10.0.0.1

$ nc -z -v mystite.com 80
Connection to mystite.com 80 port [tcp/http] succeeded!
$ curl -I mystite.com
HTTP/1.1 404 Not Found Content-length: 169 Content-Type: text/html Date: Thu, 12 Jun 2014 23:42:23 GMT Server: nginx/1.1.19 Connection: keep-alive