{"id":254578,"date":"2014-03-27T13:34:34","date_gmt":"2014-03-27T05:34:34","guid":{"rendered":"http:\/\/blog.zhenglei.net\/?p=254578"},"modified":"2014-03-27T13:44:23","modified_gmt":"2014-03-27T05:44:23","slug":"fw-install-nginx-on-centos-6-x","status":"publish","type":"post","link":"https:\/\/blog.zhenglei.net\/?p=254578","title":{"rendered":"FW:  Install nginx on Centos 6.x"},"content":{"rendered":"<p><a href=\"http:\/\/www.cyberciti.biz\/faq\/install-nginx-centos-rhel-6-server-rpm-using-yum-command\/\">http:\/\/www.cyberciti.biz\/faq\/install-nginx-centos-rhel-6-server-rpm-using-yum-command\/<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>Step #1: Install nginx repo<\/h2>\n<p><code># cd \/tmp<\/code><br \/>\n<code># wget <a href=\"http:\/\/nginx.org\/packages\/centos\/6\/noarch\/RPMS\/nginx-release-centos-6-0.el6.ngx.noarch.rpm\">http:\/\/nginx.org\/packages\/centos\/6\/noarch\/RPMS\/nginx-release-centos-6-0.el6.ngx.noarch.rpm<\/a><br \/>\n# rpm -ivh <\/code>nginx-release-centos-6-0.el6.ngx.noarch.rpm<br \/>\n<code><\/code><br \/>\n<code><\/code><\/p>\n<h2>Step #2: Install nginx web-server<\/h2>\n<p><code># yum install nginx<\/code><\/p>\n<h2>Step #3: Turn on nginx service<\/h2>\n<p><code># chkconfig nginx on<\/code><\/p>\n<h3>How do I start \/ stop \/ restart nginx web-server?<\/h3>\n<p><code># service nginx start<br \/>\n# service nginx stop<br \/>\n# service nginx restart<br \/>\n# service nginx status<br \/>\n# service nginx reload<\/code><\/p>\n<h2>Step #4: Configuration files<\/h2>\n<ol>\n<li>Default configuration directory: <kbd>\/etc\/nginx\/<\/kbd><\/li>\n<li>Default SSL and vhost config directory: <kbd>\/etc\/nginx\/conf.d\/<\/kbd><\/li>\n<li>Default log file directory: <kbd>\/var\/log\/nginx\/<\/kbd><\/li>\n<li>Default document root directory: <kbd>\/usr\/share\/nginx\/html<\/kbd><\/li>\n<li>Default configuration file: <kbd>\/etc\/nginx\/nginx.conf<\/kbd><\/li>\n<li>Default server access log file: <kbd>\/var\/log\/nginx\/access.log<\/kbd><\/li>\n<li>Default server access log file: <kbd>\/var\/log\/nginx\/error.log<\/kbd><\/li>\n<\/ol>\n<p>To edit the nginx configuration file, enter:<br \/>\n<code># nano \/etc\/nginx\/nginx.conf<\/code><\/p>\n<p>Set or update worker_processes as follows (this must be set to CPU(s) in your system. Use the <a href=\"http:\/\/www.cyberciti.biz\/faq\/install-nginx-centos-rhel-6-server-rpm-using-yum-command\/\">lscpu | grep &#8216;^CPU(s)&#8217;<\/a> command to list the number of CPUs in the server)<\/p>\n<pre>worker_processes  2;<\/pre>\n<p>Turn on gzip support:<\/p>\n<pre>gzip  on;<\/pre>\n<p>&nbsp;<\/p>\n<p>Edit the file <kbd>\/etc\/nginx\/conf.d\/default.conf<\/kbd>, enter:<br \/>\n<code># nano \/etc\/nginx\/conf.d\/default.conf<\/code><br \/>\nSet IP address and TCP port number:<\/p>\n<pre>    listen       199.241.137.179:80;<\/pre>\n<p>Set server name:<\/p>\n<pre>    server_name  vps.zhenglei.net;<\/pre>\n<p>&nbsp;<\/p>\n<p>Start the server:<br \/>\n<code># service nginx start<\/code><br \/>\nVerify that everything is working:<br \/>\n<code># netstat -tulpn | grep :80<br \/>\n# ps aux | grep nginx<\/code><\/p>\n<h2>Firewall configuration: Open TCP port # 80<\/h2>\n<p>Edit the file \/etc\/sysconfig\/iptables, enter:<br \/>\n<code># nano \/etc\/sysconfig\/iptables<\/code><br \/>\nAdd the following lines, ensuring that they appear before the final LOG and DROP lines for the INPUT chain to open port 80:<\/p>\n<pre>\u00a0\r\n-A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT<\/pre>\n<p>Save and close the file. Finally, restart the firewall:<br \/>\n<code># service iptables restart<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/www.cyberciti.biz\/faq\/install-ngi &hellip; <a href=\"https:\/\/blog.zhenglei.net\/?p=254578\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/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":[6,2,1,9],"tags":[123,122],"class_list":["post-254578","post","type-post","status-publish","format-standard","hentry","category-internet","category-linux","category-uncategorized","category-vps","tag-centos","tag-nginx"],"_links":{"self":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts\/254578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=254578"}],"version-history":[{"count":6,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts\/254578\/revisions"}],"predecessor-version":[{"id":254582,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts\/254578\/revisions\/254582"}],"wp:attachment":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=254578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=254578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=254578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}