{"id":75,"date":"2010-10-11T05:27:42","date_gmt":"2010-10-11T05:27:42","guid":{"rendered":"http:\/\/sherinsunny.wordpress.com\/?p=75"},"modified":"2010-10-11T05:27:42","modified_gmt":"2010-10-11T05:27:42","slug":"nginx-and-varnish-cache-and-reverse-proxy-to-apache","status":"publish","type":"post","link":"https:\/\/linuxmaster.in\/?p=75","title":{"rendered":"Nginx Servive static pages from Varnish Cache bypass the dynamic pages as Reverse Proxy To Apache"},"content":{"rendered":"<p>First Install nginx,varnish and apache.<\/p>\n<p>Install nginx<br \/>\n*********************<br \/>\nType the following commands to download nginx, enter:<br \/>\n# cd \/opt<br \/>\n# wget http:\/\/sysoev.ru\/nginx\/nginx-0.8.33.tar.gz<\/p>\n<p>Untar nginx, enter:<br \/>\n# tar -zxvf nginx-0.8.33.tar.gz<br \/>\n# cd nginx-0.8.33<\/p>\n<p>Configure nginx for 64 bit RHEL \/ CentOS Linux:<br \/>\n# .\/configure &#8211;without-http_autoindex_module &#8211;without-http_ssi_module &#8211;without-http_userid_module &#8211;without-http_auth_basic_module &#8211;without-http_geo_module &#8211;without-http_fastcgi_module &#8211;without-http_empty_gif_module &#8211;with-openssl=\/lib64<\/p>\n<p># make<br \/>\n# make install<br \/>\n\/usr\/local\/nginx\/sbin\/nginx<br \/>\n\/usr\/local\/nginx\/sbin\/nginx -c \/usr\/local\/nginx\/conf\/nginx.conf<\/p>\n<p>*********************************<\/p>\n<p>Change the port of apache to 81 and nginx to 80 so that the webserver port is 80.<br \/>\n\/usr\/local\/nginx\/sbin\/nginx -v<br \/>\nDefault nginx.conf (\/usr\/local\/nginx\/conf\/nginx.conf)<\/p>\n<p>*********************************************************<\/p>\n<p>#user  nobody;<br \/>\nworker_processes  1;<\/p>\n<p>#error_log  logs\/error.log;<br \/>\n#error_log  logs\/error.log  notice;<br \/>\n#error_log  logs\/error.log  info;<\/p>\n<p>#pid        logs\/nginx.pid;<\/p>\n<p>events {<br \/>\n    worker_connections  1024;<br \/>\n}<\/p>\n<p>http {<br \/>\n    include       mime.types;<br \/>\n    default_type  application\/octet-stream;<\/p>\n<p>    #log_format  main  &#8216;$remote_addr &#8211; $remote_user [$time_local] &#8220;$request&#8221; &#8216;<br \/>\n    #                  &#8216;$status $body_bytes_sent &#8220;$http_referer&#8221; &#8216;<br \/>\n    #                  &#8216;&#8221;$http_user_agent&#8221; &#8220;$http_x_forwarded_for&#8221;&#8216;;<\/p>\n<p>    #access_log  logs\/access.log  main;<\/p>\n<p>    sendfile        on;<br \/>\n    #tcp_nopush     on;<\/p>\n<p>    #keepalive_timeout  0;<br \/>\n    keepalive_timeout  65;<br \/>\nupstream cache_servers {<br \/>\n      server localhost:6081 max_fails=3 fail_timeout=30s;<br \/>\n    }<br \/>\n    #gzip  on;<br \/>\nserver {<br \/>\n  access_log off;<\/p>\n<p>  error_log  logs\/vhost-error_log warn;<br \/>\n  listen    80;<br \/>\n  server_name  emegano.com;<\/p>\n<p>  # uncomment location below to make nginx serve static files instead of Apache<br \/>\n  # NOTE this will cause issues with bandwidth accounting as files wont be logged<br \/>\n  location ~* \\.(gif|jpg|jpeg|3gp|wmv|avi|mpg|mpeg|mp4|js|css)$ {<br \/>\n   root   \/var\/www\/html\/emegano.com;<br \/>\n  }<\/p>\n<p>  location \/ {<br \/>\n   proxy_send_timeout   90;<br \/>\n   proxy_read_timeout   90;<\/p>\n<p>   proxy_buffer_size    4k;<br \/>\n   # you can increase proxy_buffers here to suppress &#8220;an upstream response<br \/>\n   #  is buffered to a temporary file&#8221; warning<br \/>\n   proxy_buffers     16 32k;<br \/>\n   proxy_busy_buffers_size 64k;<br \/>\n   proxy_temp_file_write_size 64k;<\/p>\n<p>   proxy_connect_timeout 30s;<\/p>\n<p>  # proxy_redirect  http:\/\/www.emegano.com:81   http:\/\/www.emegano.com;<br \/>\n  # proxy_redirect  http:\/\/emegano.com:81   http:\/\/emegano.com;<\/p>\n<p>   proxy_pass  http:\/\/41.223.52.100:6081;<br \/>\n  #proxy_pass http:\/\/cache_servers\/;<br \/>\n # proxy_redirect http:\/\/cache_servers\/ http:\/\/$host:$server_port\/;<\/p>\n<p>   proxy_set_header   Host   $host;<br \/>\n   proxy_set_header   X-Real-IP  $remote_addr;<br \/>\n   proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;<br \/>\n  }<br \/>\n }<\/p>\n<p>    # another virtual host using mix of IP-, name-, and port-based configuration<br \/>\n    #<br \/>\n    #server {<br \/>\n    #    listen       8000;<br \/>\n    #    listen       somename:8080;<br \/>\n    #    server_name  somename  alias  another.alias;<\/p>\n<p>    #    location \/ {<br \/>\n    #        root   html;<br \/>\n    #        index  index.html index.htm;<br \/>\n    #    }<br \/>\n    #}<\/p>\n<p>    # HTTPS server<br \/>\n    #<br \/>\n    #server {<br \/>\n    #    listen       443;<br \/>\n    #    server_name  localhost;<\/p>\n<p>    #    ssl                  on;<br \/>\n    #    ssl_certificate      cert.pem;<br \/>\n    #    ssl_certificate_key  cert.key;<\/p>\n<p>    #    ssl_session_timeout  5m;<\/p>\n<p>    #    ssl_protocols  SSLv2 SSLv3 TLSv1;<br \/>\n    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;<br \/>\n    #    ssl_prefer_server_ciphers   on;<\/p>\n<p>    #    location \/ {<br \/>\n    #        root   html;<br \/>\n    #        index  index.html index.htm;<br \/>\n    #    }<br \/>\n    #}<\/p>\n<p>}<br \/>\n*****************************************************<br \/>\nyum install logrotate libgomp gcc cpp binutils kernel-headers glibc-headers glibc-devel<br \/>\nrpm -Uvh varnish-1.1.2-5el5.x86_64.rpm varnish-libs-1.1.2-5el5.x86_64.rpm<br \/>\nyum install varnish.x86_64<br \/>\nfor A in varnish varnishlog ; do chkconfig $A on ; service $A start ; done<br \/>\nVarnish default.vcl<br \/>\n*******************************************************<br \/>\ncat \/etc\/varnish\/default.vcl<br \/>\n#This is a basic VCL configuration file for varnish.  See the vcl(7)<br \/>\n#man page for details on VCL syntax and semantics.<br \/>\n#<br \/>\n#Default backend definition.  Set this to point to your content<br \/>\n#server.<\/p>\n<p>backend default {<br \/>\n  .host = &#8220;41.223.52.100&#8221;;<br \/>\n  .port = &#8220;81&#8221;;<br \/>\n}<br \/>\n#<br \/>\n#Below is a commented-out copy of the default VCL logic.  If you<br \/>\n#redefine any of these subroutines, the built-in logic will be<br \/>\n#appended to your code.<br \/>\n#<br \/>\n#sub vcl_recv {<br \/>\n #   if (req.request != &#8220;GET&#8221; &amp;&amp;<br \/>\n  #    req.request != &#8220;HEAD&#8221; &amp;&amp;<br \/>\n   #   req.request != &#8220;PUT&#8221; &amp;&amp;<br \/>\n    #  req.request != &#8220;POST&#8221; &amp;&amp;<br \/>\n     # req.request != &#8220;TRACE&#8221; &amp;&amp;<br \/>\n      #req.request != &#8220;OPTIONS&#8221; &amp;&amp;<br \/>\n     # req.request != &#8220;DELETE&#8221;) {<br \/>\n#        \/* Non-RFC2616 or CONNECT which is weird. *\/<br \/>\n      #  return (pipe);<br \/>\n   # }<br \/>\n#    if (req.request != &#8220;GET&#8221; &amp;&amp; req.request != &#8220;HEAD&#8221;) {<br \/>\n#        \/* We only deal with GET and HEAD by default *\/<br \/>\n#        return (pass);<br \/>\n#    }<br \/>\n#    if (req.http.Authorization || req.http.Cookie) {<br \/>\n#        \/* Not cacheable by default *\/<br \/>\n#        return (pass);<br \/>\n#    }<br \/>\n#    return (lookup);<br \/>\n#}<br \/>\n#<br \/>\n#sub vcl_pipe {<br \/>\n#    # Note that only the first request to the backend will have<br \/>\n#    # X-Forwarded-For set.  If you use X-Forwarded-For and want to<br \/>\n#    # have it set for all requests, make sure to have:<br \/>\n#    # set req.http.connection = &#8220;close&#8221;;<br \/>\n#    # here.  It is not set by default as it might break some broken web<br \/>\n#    # applications, like IIS with NTLM authentication.<br \/>\n#    return (pipe);<br \/>\n#}<br \/>\n#<br \/>\n#sub vcl_pass {<br \/>\n#    return (pass);<br \/>\n#}<br \/>\n#<br \/>\n#sub vcl_hash {<br \/>\n#    set req.hash += req.url;<br \/>\n#    if (req.http.host) {<br \/>\n#        set req.hash += req.http.host;<br \/>\n#    } else {<br \/>\n#        set req.hash += server.ip;<br \/>\n#    }<br \/>\n#    return (hash);<br \/>\n#}<br \/>\n#<br \/>\n#sub vcl_hit {<br \/>\n#    if (!obj.cacheable) {<br \/>\n#        return (pass);<br \/>\n#    }<br \/>\n#    return (deliver);<br \/>\n#}<br \/>\n#<br \/>\n#sub vcl_miss {<br \/>\n#    return (fetch);<br \/>\n#}<br \/>\n#<br \/>\n#sub vcl_fetch {<br \/>\n#    if (!obj.cacheable) {<br \/>\n#        return (pass);<br \/>\n#    }<br \/>\n#    if (obj.http.Set-Cookie) {<br \/>\n#        return (pass);<br \/>\n#    }<br \/>\n#    set obj.prefetch =  -30s;<br \/>\n#    return (deliver);<br \/>\n#}<br \/>\n#<br \/>\n#sub vcl_deliver {<br \/>\n#    return (deliver);<br \/>\n#}<br \/>\n#<br \/>\n#sub vcl_discard {<br \/>\n#    \/* XXX: Do not redefine vcl_discard{}, it is not yet supported *\/<br \/>\n#    return (discard);<br \/>\n#}<br \/>\n#<br \/>\n#sub vcl_prefetch {<br \/>\n#    \/* XXX: Do not redefine vcl_prefetch{}, it is not yet supported *\/<br \/>\n#    return (fetch);<br \/>\n#}<br \/>\n#<br \/>\n#sub vcl_timeout {<br \/>\n#    \/* XXX: Do not redefine vcl_timeout{}, it is not yet supported *\/<br \/>\n#    return (discard);<br \/>\n#}<br \/>\n#<br \/>\n#sub vcl_error {<br \/>\n#    set obj.http.Content-Type = &#8220;text\/html; charset=utf-8&#8243;;<br \/>\n#    synthetic {&#8221;<\/p>\n<p>#    &#8220;} obj.status &#8221; &#8221; obj.response {&#8221;<br \/>\n#<br \/>\n#<br \/>\n#   Error &#8220;} obj.status &#8221; &#8221; obj.response {&#8221;<br \/>\n#    <\/p>\n<p>&#8220;} obj.response {&#8220;<\/p>\n<p>#   Guru Meditation:<br \/>\n#  XID: &#8220;} req.xid {&#8221;<br \/>\n#    <\/p>\n<hr \/>\n<p>#    <\/p>\n<address>\n#       <a href=\"http:\/\/www.sherinsunny.com\/\">Varnish cache server<\/a><br \/>\n#    <\/address>\n<p> #};<br \/>\n#    return (deliver);<br \/>\n#}<\/p>\n<p>***************************************************<br \/>\nVarnish<br \/>\n***************************************************<br \/>\n cat \/etc\/sysconfig\/varnish<br \/>\n# Configuration file for varnish<br \/>\n#<br \/>\n# \/etc\/init.d\/varnish expects the variable $DAEMON_OPTS to be set from this<br \/>\n# shell script fragment.<br \/>\n#<\/p>\n<p># Maximum number of open files (for ulimit -n)<br \/>\nNFILES=131072<\/p>\n<p># Locked shared memory (for ulimit -l)<br \/>\n# Default log size is 82MB + header<br \/>\nMEMLOCK=82000<\/p>\n<p># Maximum size of corefile (for ulimit -c). Default in Fedora is 0<br \/>\n# DAEMON_COREFILE_LIMIT=&#8221;unlimited&#8221;<\/p>\n<p># This file contains 4 alternatives, please use only one.<\/p>\n<p>## Alternative 1, Minimal configuration, no VCL<br \/>\n#<br \/>\n# Listen on port 6081, administration on localhost:6082, and forward to<br \/>\n# content server on localhost:8080.  Use a fixed-size cache file.<br \/>\n#<br \/>\n#DAEMON_OPTS=&#8221;-a 41.223.52.100:6081 \\<br \/>\n #            -T localhost:6082 \\<br \/>\n       #      -b localhost:8080 \\<br \/>\n        #     -u varnish -g varnish \\<br \/>\n         #    -s file,\/var\/lib\/varnish\/varnish_storage.bin,1G&#8221;<\/p>\n<p>## Alternative 2, Configuration with VCL<br \/>\n#<br \/>\n# Listen on port 6081, administration on localhost:6082, and forward to<br \/>\n# one content server selected by the vcl file, based on the request.  Use a<br \/>\n# fixed-size cache file.<br \/>\n#<br \/>\nDAEMON_OPTS=&#8221;-a 41.223.52.100:6081 \\<br \/>\n             -T localhost:6082 \\<br \/>\n             -f \/etc\/varnish\/default.vcl \\<br \/>\n             -u varnish -g varnish \\<br \/>\n             -s file,\/var\/lib\/varnish\/varnish_storage.bin,1G&#8221;<\/p>\n<p>## Alternative 3, Advanced configuration<br \/>\n#<br \/>\n# See varnishd(1) for more information.<br \/>\n#<br \/>\n# # Main configuration file. You probably want to change it \ud83d\ude42<br \/>\n VARNISH_VCL_CONF=\/etc\/varnish\/default.vcl<br \/>\n#<br \/>\n# # Default address and port to bind to<br \/>\n# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify<br \/>\n# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.<br \/>\n# VARNISH_LISTEN_ADDRESS=<br \/>\n VARNISH_LISTEN_PORT=6081<br \/>\n#<br \/>\n# # Telnet admin interface listen address and port<br \/>\n VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1<br \/>\n VARNISH_ADMIN_LISTEN_PORT=6082<br \/>\n#<br \/>\n# # The minimum number of worker threads to start<br \/>\n VARNISH_MIN_THREADS=1<br \/>\n#<br \/>\n# # The Maximum number of worker threads to start<br \/>\n VARNISH_MAX_THREADS=1000<br \/>\n#<br \/>\n# # Idle timeout for worker threads<br \/>\n VARNISH_THREAD_TIMEOUT=120<br \/>\n#<br \/>\n# # Cache file location<br \/>\n VARNISH_STORAGE_FILE=\/var\/lib\/varnish\/varnish_storage.bin<br \/>\n#<br \/>\n# # Cache file size: in bytes, optionally using k \/ M \/ G \/ T suffix,<br \/>\n# # or in percentage of available disk space using the % suffix.<br \/>\n VARNISH_STORAGE_SIZE=1G<br \/>\n#<br \/>\n# # Backend storage specification<br \/>\n VARNISH_STORAGE=&#8221;file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}&#8221;<br \/>\n#<br \/>\n# # Default TTL used when the backend does not specify one<br \/>\n VARNISH_TTL=120<br \/>\n#<br \/>\n# # DAEMON_OPTS is used by the init script.  If you add or remove options, make<br \/>\n# # sure you update this section, too.<br \/>\n DAEMON_OPTS=&#8221;-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \\<br \/>\n              -f ${VARNISH_VCL_CONF} \\<br \/>\n              -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \\<br \/>\n              -t ${VARNISH_TTL} \\<br \/>\n              -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \\<br \/>\n              -u varnish -g varnish \\<br \/>\n              -s ${VARNISH_STORAGE}&#8221;<\/p>\n<p>## Alternative 4, Do It Yourself. See varnishd(1) for more information.<br \/>\n#<br \/>\n# DAEMON_OPTS=&#8221;&#8221;<br \/>\n*******************************************************************************************************************************************<\/p>\n","protected":false},"excerpt":{"rendered":"<p>First Install nginx,varnish and apache. Install nginx ********************* Type the following commands to download nginx, enter: # cd \/opt # wget http:\/\/sysoev.ru\/nginx\/nginx-0.8.33.tar.gz Untar nginx, enter: # tar -zxvf nginx-0.8.33.tar.gz # cd nginx-0.8.33 Configure nginx for 64 bit RHEL \/ CentOS Linux: # .\/configure &#8211;without-http_autoindex_module &#8211;without-http_ssi_module &#8211;without-http_userid_module &#8211;without-http_auth_basic_module &#8211;without-http_geo_module &#8211;without-http_fastcgi_module &#8211;without-http_empty_gif_module &#8211;with-openssl=\/lib64 # make # make &hellip; <a href=\"https:\/\/linuxmaster.in\/?p=75\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Nginx Servive static pages from Varnish Cache bypass the dynamic pages as Reverse Proxy To Apache&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/linuxmaster.in\/index.php?rest_route=\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxmaster.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxmaster.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxmaster.in\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxmaster.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=75"}],"version-history":[{"count":0,"href":"https:\/\/linuxmaster.in\/index.php?rest_route=\/wp\/v2\/posts\/75\/revisions"}],"wp:attachment":[{"href":"https:\/\/linuxmaster.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxmaster.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxmaster.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}