{"id":5578,"date":"2016-01-27T08:37:12","date_gmt":"2016-01-27T00:37:12","guid":{"rendered":"http:\/\/rmohan.com\/?p=5578"},"modified":"2016-01-27T08:37:12","modified_gmt":"2016-01-27T00:37:12","slug":"nginx-has-load-balancer","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=5578","title":{"rendered":"nginx  has load balancer"},"content":{"rendered":"<p>nginx is a high performance web server software. It is a much more flexible and lightweight program than apache.<\/p>\n<p>yum install epel-release<\/p>\n<p>yum install nginx<\/p>\n<p>ifconfig eth0 | grep inet | awk &#8216;{ print $2 }&#8217;<\/p>\n<p>wget \u2013no-cookies \u2013no-check-certificate \u2013header \u201cCookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie\u201d \u201chttp:\/\/download.oracle.com\/otn-pub\/java\/jdk\/8u60-b27\/jdk-8u60-linux-x64.tar.gz\u201d<br \/>\nwget http:\/\/mirror.nus.edu.sg\/apache\/tomcat\/tomcat-8\/v8.0.30\/bin\/apache-tomcat-8.0.30.tar.gz<br \/>\ntar xzf jdk-8u40-linux-i586.tar.gz<br \/>\nmkdir \/usr\/java\/<\/p>\n<p>cd \/usr\/java\/jdk1.8.0_40\/<br \/>\n[root@cluster1 java]# ln -s \/usr\/java\/jdk1.8.0_40\/bin\/java \/usr\/bin\/java<br \/>\n[root@cluster1 java]# alternatives \u2013install \/usr\/java\/jdk1.8.0_40\/bin\/java java \/usr\/java\/jdk1.8.0_40\/bin\/java 2<\/p>\n<p>alternatives &#8211;install \/usr\/java\/jdk1.8.0_40\/bin\/java java \/usr\/java\/jdk1.8.0_40\/bin\/java 2<br \/>\nalternatives &#8211;config java<\/p>\n<p>vi \/etc\/profile.d\/java.sh<br \/>\nexport JAVA_HOME=\/usr\/java\/jdk1.8.0_25<br \/>\nPATH=$JAVA_HOME\/bin:$PATH<br \/>\nexport PATH=$PATH:$JAVA_HOME<br \/>\nexport JRE_HOME=\/usr\/java\/jdk1.8.0_25\/jre<br \/>\nexport PATH=$PATH:\/usr\/java\/jdk1.8.0_25\/bin:\/usr\/java\/jdk1.8.0_25\/jre\/bin<\/p>\n<p>Three, Tomcat load balancing configuration<\/p>\n<p>When Nginx start loading default configuration file \/etc\/nginx\/nginx.conf, while nginx.conf in references \/etc\/nginx\/conf.d catalog all .conf files.<\/p>\n<p>Therefore, some of their own custom configuration can be written to a separate .conf files, as long as the files are placed \/etc\/nginx\/conf.d this directory can be, and easy maintenance.<\/p>\n<p>Create tomcats.conf: vi \/etc\/nginx\/conf.d\/tomcats.conf, which reads as follows:<\/p>\n<p>\/usr\/tomcat\/apache-tomcat-8.0.30\/bin\/startup.sh<\/p>\n<p>vi \/etc\/nginx\/conf.d\/tomcats.conf<\/p>\n<p>upstream tomcats {<br \/>\nip_hash;<br \/>\nserver 192.168.1.60:8080;<br \/>\nserver 192.168.1.62:8080;<br \/>\nserver 192.168.0.63:8080;<br \/>\n}<\/p>\n<p>Modify default.conf: vi \/etc\/nginx\/conf.d\/default.conf, amend as follows:<br \/>\nvi \/etc\/nginx\/conf.d\/default.conf<br \/>\nneed to amend the below lines<br \/>\n#location \/ {<br \/>\n#\u00a0\u00a0 root\u00a0\u00a0 \/usr\/share\/nginx\/html;<br \/>\n#\u00a0\u00a0\u00a0 index\u00a0 index.html index.htm;<br \/>\n#}<\/p>\n<p># new configuration default forwards the request to tomcats. conf configuration upstream processing<br \/>\nlocation \/ {<br \/>\nproxy_set_header Host $host;<br \/>\nproxy_set_header X-Real-IP $remote_addr;<br \/>\nproxy_set_header REMOTE-HOST $remote_addr;<br \/>\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br \/>\nproxy_pass http:\/\/tomcats;<br \/>\n}<\/p>\n<p>After saving reload the configuration: nginx -s reload<\/p>\n<p>Four separate static resource configuration<\/p>\n<p>Modify default.conf: vi \/etc\/nginx\/conf.d\/default.conf, add the following configuration:<br \/>\nvi \/etc\/nginx\/conf.d\/default.conf<\/p>\n<p>All js, css requests related static resource files processed by Nginx<\/p>\n<p>location ~.*\\.(js|css)$ {<br \/>\nroot\u00a0\u00a0\u00a0 \/opt\/static-resources;<br \/>\nexpires\u00a0\u00a0\u00a0\u00a0 12h;<br \/>\n}<\/p>\n<p>Request # All photos and other multimedia-related static resource files is handled by Nginx<\/p>\n<p>location ~.*\\.(html|jpg|jpeg|png|bmp|gif|ico|mp3|mid|wma|mp4|swf|flv|rar|zip|txt|doc|ppt|xls|pdf)$ {<br \/>\nroot\u00a0\u00a0\u00a0 \/opt\/static-resources;<br \/>\nexpires\u00a0\u00a0\u00a0\u00a0 7d;<br \/>\n}<\/p>\n<p>Create a Directory for the Certificate<br \/>\nmkdir \/etc\/nginx\/ssl<br \/>\ncd \/etc\/nginx\/ssl<br \/>\nopenssl genrsa -des3 -out server.key 2048<br \/>\nopenssl req -new -key server.key -out server.csr<br \/>\ncp server.key server.key.org<br \/>\nopenssl rsa -in server.key.org -out server.key<br \/>\nopenssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt<\/p>\n<p>server {<br \/>\nlisten 80;<br \/>\nlisten 443 default ssl;<br \/>\nserver_name cluster1.rmohan.com;<br \/>\nkeepalive_timeout\u00a0\u00a0 70;<br \/>\n# ssl on;<br \/>\nssl_certificate\u00a0\u00a0\u00a0\u00a0 \/etc\/nginx\/ssl\/server.crt;<br \/>\nssl_certificate_key \/etc\/nginx\/ssl\/server.key;<br \/>\nssl_protocols\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TLSv1 TLSv1.1 TLSv1.2;<br \/>\nssl_ciphers\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 HIGH:!aNULL:!MD5;<br \/>\nssl_prefer_server_ciphers\u00a0\u00a0 on;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>nginx is a high performance web server software. It is a much more flexible and lightweight program than apache.<\/p>\n<p>yum install epel-release<\/p>\n<p>yum install nginx<\/p>\n<p>ifconfig eth0 | grep inet | awk &#8216;{ print $2 }&#8217;<\/p>\n<p>wget \u2013no-cookies \u2013no-check-certificate \u2013header \u201cCookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie\u201d \u201chttp:\/\/download.oracle.com\/otn-pub\/java\/jdk\/8u60-b27\/jdk-8u60-linux-x64.tar.gz\u201d wget http:\/\/mirror.nus.edu.sg\/apache\/tomcat\/tomcat-8\/v8.0.30\/bin\/apache-tomcat-8.0.30.tar.gz tar xzf jdk-8u40-linux-i586.tar.gz mkdir \/usr\/java\/<\/p>\n<p>cd \/usr\/java\/jdk1.8.0_40\/ [root@cluster1 java]# [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5578"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5578"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5578\/revisions"}],"predecessor-version":[{"id":5579,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5578\/revisions\/5579"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}