{"id":13,"date":"2011-08-09T22:55:54","date_gmt":"2011-08-09T22:55:54","guid":{"rendered":"http:\/\/shuran.cn\/?p=13"},"modified":"2012-02-08T04:09:48","modified_gmt":"2012-02-08T04:09:48","slug":"nginx-%e5%9c%a8redhat5%e5%ae%89%e8%a3%85%e8%bf%87%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.shuran.cn\/?p=13","title":{"rendered":"Nginx \u5728RedHat5\u5b89\u88c5\u8fc7\u7a0b"},"content":{"rendered":"<p>\u4e00\u3001Nginx\u76f8\u5173\u8d44\u6599<\/p>\n<p>\u4e3b\u7ad9\uff1ahttp:\/\/www.nginx.org\/<\/p>\n<p>Nginx\u4e2d\u6587\u7ef4\u57fa:http:\/\/wiki.nginx.org\/NginxChs<\/p>\n<p>Nginx\u4e2d\u6587\u8d44\u6599\uff1ahttp:\/\/blog.s135.com\/index.php<\/p>\n<p>http:\/\/www.51nginx.net\/<\/p>\n<p>\u4e8c\u3001\u521b\u5efawww\u7528\u6237\u548c\u7ec4<\/p>\n<p>\/usr\/sbin\/groupadd www<br \/>\n\/usr\/sbin\/useradd -g www www<br \/>\nmkdir -p \/data0\/htdocs\/blog<br \/>\nchmod +w \/data0\/htdocs\/blog<br \/>\nchown -R www:www \/data0\/htdocs\/blog<br \/>\nmkdir -p \/data0\/htdocs\/www<br \/>\nchmod +w \/data0\/htdocs\/www<br \/>\nchown -R www:www \/data0\/htdocs\/www<\/p>\n<p>\u4e09\u3001\u5b89\u88c5nginx-1.0.4<br \/>\n\u3000\u30001\u3001\u5b89\u88c5Nginx\u6240\u9700\u7684pcre\u5e93\uff1a<\/p>\n<p>wget ftp:\/\/ftp.csx.cam.ac.uk\/pub\/software\/programming\/pcre\/pcre-8.12.tar.gz<\/p>\n<p>tar zxvf pcre-8.12.tar.gz<br \/>\ncd pcre-8.12\/<br \/>\n.\/configure<br \/>\nmake &amp;&amp; make install<\/p>\n<p>\u53ef\u80fd\u9700\u8981\u7684\u5e93\uff1a<\/p>\n<p>x86_64 \u7cfb\u7edf<\/p>\n<p>wget http:\/\/blog.s135.com\/soft\/linux\/nginx_php\/rpm\/x86_64\/libjpeg-devel-6b-33.x86_64.rpm<br \/>\nrpm -ivh libjpeg-devel-6b-33.x86_64.rpm<br \/>\nwget http:\/\/blog.s135.com\/soft\/linux\/nginx_php\/rpm\/x86_64\/freetype-devel-2.1.9-1.x86_64.rpm<br \/>\nrpm -ivh freetype-devel-2.1.9-1.x86_64.rpm<br \/>\nwget http:\/\/blog.s135.com\/soft\/linux\/nginx_php\/rpm\/x86_64\/libpng-devel-1.2.7-1.x86_64.rpm<br \/>\nrpm -ivh libpng-devel-1.2.7-1.x86_64.rpm<\/p>\n<p>\u3000\u30002\u3001\u5b89\u88c5Nginx<\/p>\n<p>tar zxvf nginx-1.0.4.tar.gz<br \/>\ncd nginx-1.0.4\/<br \/>\n.\/configure --user=www --group=www --prefix=\/usr\/local\/webserver\/nginx --with-http_stub_status_module --with-http_ssl_module<br \/>\nmake &amp;&amp; make install<\/p>\n<p>\u3000\u30003\u3001\u521b\u5efaNginx\u65e5\u5fd7\u76ee\u5f55<\/p>\n<p>mkdir -p \/data1\/logs<br \/>\nchmod +w \/data1\/logs<br \/>\nchown -R www:www \/data1\/logs<\/p>\n<p>\u3000\u30004\u3001\u521b\u5efaNginx\u914d\u7f6e\u6587\u4ef6<br \/>\n\u3000\u3000\u2460\u3001\u5728\/usr\/local\/webserver\/nginx\/conf\/\u76ee\u5f55\u4e2d\u521b\u5efanginx.conf\u6587\u4ef6\uff1a<\/p>\n<p>rm -f \/usr\/local\/webserver\/nginx\/conf\/nginx.conf<br \/>\nvi \/usr\/local\/webserver\/nginx\/conf\/nginx.conf<\/p>\n<p>\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<p>Xml\u4ee3\u7801<br \/>\nuser www www;<br \/>\nworker_processes 4;<\/p>\n<p>error_log \/usr\/local\/loadbalancer\/logs\/nginx_error.log crit;<\/p>\n<p>pid \/usr\/local\/loadbalancer\/nginx\/nginx.pid;<\/p>\n<p>#Specifies the value for maximum file descriptors that can be opened by this process.<br \/>\nworker_rlimit_nofile 1024;<\/p>\n<p>events {<br \/>\nuse epoll;<br \/>\nworker_connections 1024;<br \/>\n}<\/p>\n<p>http {<br \/>\ninclude mime.types;<br \/>\ndefault_type application\/octet-stream;<\/p>\n<p>log_format main '$remote_addr - $remote_user [$time_local] \"$request\" '<br \/>\n'$status $body_bytes_sent \"$http_referer\" '<br \/>\n'\"$http_user_agent\" \"$http_x_forwarded_for\"';<\/p>\n<p>server_names_hash_bucket_size 128;<br \/>\nclient_header_buffer_size 32k;<br \/>\nlarge_client_header_buffers 4 32k;<br \/>\nclient_max_body_size 8m;<\/p>\n<p>sendfile on;<br \/>\ntcp_nopush on;<\/p>\n<p>keepalive_timeout 60;<\/p>\n<p>tcp_nodelay on;<\/p>\n<p>gzip on;<br \/>\ngzip_min_length 1k;<br \/>\ngzip_buffers 4 16k;<br \/>\ngzip_http_version 1.0;<br \/>\ngzip_comp_level 2;<br \/>\ngzip_types text\/plain application\/x-javascript text\/css application\/xml;<br \/>\ngzip_vary on;<\/p>\n<p>server {<br \/>\nlisten 80;<br \/>\nserver_name www.xxx.com xxx.com *.xxx.com;<\/p>\n<p>location \/ {<br \/>\nproxy_pass http:\/\/www.xxx.com:8080;<br \/>\n}<\/p>\n<p>log_format access '$remote_addr - $remote_user [$time_local] \"$request\" '<br \/>\n'$status $body_bytes_sent \"$http_referer\" '<br \/>\n'\"$http_user_agent\" $http_x_forwarded_for';<br \/>\naccess_log \/usr\/local\/loadbalancer\/logs\/xxx_access.log access;<br \/>\n}<\/p>\n<p>server {<br \/>\nlisten 80;<br \/>\nserver_name www.ffff.com ffff.com *.ffff.com;<\/p>\n<p>location \/ {<br \/>\nproxy_pass http:\/\/www.fff.com:8082;<br \/>\n}<\/p>\n<p>log_format access '$remote_addr - $remote_user [$time_local] \"$request\" '<br \/>\n'$status $body_bytes_sent \"$http_referer\" '<br \/>\n'\"$http_user_agent\" $http_x_forwarded_for';<br \/>\naccess_log \/usr\/local\/loadbalancer\/logs\/fff_access.log access;<br \/>\n}<br \/>\n}<\/p>\n<p>user www www;<br \/>\nworker_processes 4;<\/p>\n<p>error_log \/usr\/local\/loadbalancer\/logs\/nginx_error.log crit;<\/p>\n<p>pid \/usr\/local\/loadbalancer\/nginx\/nginx.pid;<\/p>\n<p>#Specifies the value for maximum file descriptors that can be opened by this process.<br \/>\nworker_rlimit_nofile 1024;<\/p>\n<p>events {<br \/>\nuse epoll;<br \/>\nworker_connections 1024;<br \/>\n}<\/p>\n<p>http {<br \/>\ninclude mime.types;<br \/>\ndefault_type application\/octet-stream;<\/p>\n<p>log_format main '$remote_addr - $remote_user [$time_local] \"$request\" '<br \/>\n'$status $body_bytes_sent \"$http_referer\" '<br \/>\n'\"$http_user_agent\" \"$http_x_forwarded_for\"';<\/p>\n<p>server_names_hash_bucket_size 128;<br \/>\nclient_header_buffer_size 32k;<br \/>\nlarge_client_header_buffers 4 32k;<br \/>\nclient_max_body_size 8m;<\/p>\n<p>sendfile on;<br \/>\ntcp_nopush on;<\/p>\n<p>keepalive_timeout 60;<\/p>\n<p>tcp_nodelay on;<\/p>\n<p>gzip on;<br \/>\ngzip_min_length 1k;<br \/>\ngzip_buffers 4 16k;<br \/>\ngzip_http_version 1.0;<br \/>\ngzip_comp_level 2;<br \/>\ngzip_types text\/plain application\/x-javascript text\/css application\/xml;<br \/>\ngzip_vary on;<\/p>\n<p>server {<br \/>\nlisten 80;<br \/>\nserver_name www.xxx.com xxx.com *.xxx.com;<\/p>\n<p>location \/ {<br \/>\nproxy_pass http:\/\/www.xxx.com:8080;<br \/>\n}<\/p>\n<p>log_format access '$remote_addr - $remote_user [$time_local] \"$request\" '<br \/>\n'$status $body_bytes_sent \"$http_referer\" '<br \/>\n'\"$http_user_agent\" $http_x_forwarded_for';<br \/>\naccess_log \/usr\/local\/loadbalancer\/logs\/xxx_access.log access;<br \/>\n}<\/p>\n<p>server {<br \/>\nlisten 80;<br \/>\nserver_name www.ffff.com ffff.com *.ffff.com;<\/p>\n<p>location \/ {<br \/>\nproxy_pass http:\/\/www.fff.com:8082;<br \/>\n}<\/p>\n<p>log_format access '$remote_addr - $remote_user [$time_local] \"$request\" '<br \/>\n'$status $body_bytes_sent \"$http_referer\" '<br \/>\n'\"$http_user_agent\" $http_x_forwarded_for';<br \/>\naccess_log \/usr\/local\/loadbalancer\/logs\/fff_access.log access;<br \/>\n}<br \/>\n}<\/p>\n<p>\u3000\u3000\u2461\u3001\u5728\/usr\/local\/webserver\/nginx\/conf\/\u76ee\u5f55\u4e2d\u521b\u5efafcgi.conf\u6587\u4ef6\uff1a<\/p>\n<p>vi \/usr\/local\/webserver\/nginx\/conf\/fcgi.conf<\/p>\n<p>\u3000\u3000\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<p>\u5f15\u7528<br \/>\nfastcgi_param GATEWAY_INTERFACE CGI\/1.1;<br \/>\nfastcgi_param SERVER_SOFTWARE nginx;<\/p>\n<p>fastcgi_param QUERY_STRING $query_string;<br \/>\nfastcgi_param REQUEST_METHOD $request_method;<br \/>\nfastcgi_param CONTENT_TYPE $content_type;<br \/>\nfastcgi_param CONTENT_LENGTH $content_length;<\/p>\n<p>fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br \/>\nfastcgi_param SCRIPT_NAME $fastcgi_script_name;<br \/>\nfastcgi_param REQUEST_URI $request_uri;<br \/>\nfastcgi_param DOCUMENT_URI $document_uri;<br \/>\nfastcgi_param DOCUMENT_ROOT $document_root;<br \/>\nfastcgi_param SERVER_PROTOCOL $server_protocol;<\/p>\n<p>fastcgi_param REMOTE_ADDR $remote_addr;<br \/>\nfastcgi_param REMOTE_PORT $remote_port;<br \/>\nfastcgi_param SERVER_ADDR $server_addr;<br \/>\nfastcgi_param SERVER_PORT $server_port;<br \/>\nfastcgi_param SERVER_NAME $server_name;<\/p>\n<p># PHP only, required if PHP was built with --enable-force-cgi-redirect<br \/>\nfastcgi_param REDIRECT_STATUS 200;<\/p>\n<p>\u3000\u30005\u3001\u542f\u52a8Nginx<\/p>\n<p>ulimit -SHn 65535<br \/>\n\/usr\/local\/webserver\/nginx\/sbin\/nginx<\/p>\n<p>--------------------------------------------------------------------------------<\/p>\n<p>\u3000\u3000\u516d\u3001\u5728\u4e0d\u505c\u6b62Nginx\u670d\u52a1\u7684\u60c5\u51b5\u4e0b\u5e73\u6ed1\u53d8\u66f4Nginx\u914d\u7f6e<br \/>\n\u3000\u30001\u3001\u4fee\u6539\/usr\/local\/webserver\/nginx\/conf\/nginx.conf\u914d\u7f6e\u6587\u4ef6\u540e\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5\u914d\u7f6e\u6587\u4ef6\u662f\u5426\u6b63\u786e\uff1a<\/p>\n<p>\/usr\/local\/webserver\/nginx\/sbin\/nginx -t<\/p>\n<p>\u3000\u3000\u5982\u679c\u5c4f\u5e55\u663e\u793a\u4ee5\u4e0b\u4e24\u884c\u4fe1\u606f\uff0c\u8bf4\u660e\u914d\u7f6e\u6587\u4ef6\u6b63\u786e\uff1a<br \/>\n\u3000\u3000the configuration file \/usr\/local\/webserver\/nginx\/conf\/nginx.conf syntax is ok<br \/>\n\u3000\u3000the configuration file \/usr\/local\/webserver\/nginx\/conf\/nginx.conf was tested successfully<\/p>\n<p>\u3000\u30002\u3001\u5e73\u6ed1\u91cd\u542f\uff1a<br \/>\n\u3000\u3000\u2460\u3001\u5bf9\u4e8eNginx 0.8.x\u7248\u672c\uff0c\u73b0\u5728\u5e73\u6ed1\u91cd\u542fNginx\u914d\u7f6e\u975e\u5e38\u7b80\u5355\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\uff1a<\/p>\n<p>\/usr\/local\/webserver\/nginx\/sbin\/nginx -s reload<\/p>\n<p>--------------------------------------------------------------------------------<\/p>\n<p>\u3000\u3000\u4e03\u3001\u7f16\u5199\u6bcf\u5929\u5b9a\u65f6\u5207\u5272Nginx\u65e5\u5fd7\u7684\u811a\u672c<br \/>\n\u3000\u30001\u3001\u521b\u5efa\u811a\u672c\/usr\/local\/webserver\/nginx\/sbin\/cut_nginx_log.sh<\/p>\n<p>vi \/usr\/local\/webserver\/nginx\/sbin\/cut_nginx_log.sh<\/p>\n<p>\u3000\u3000\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<p>\u5f15\u7528<br \/>\n#!\/bin\/bash<br \/>\n# This script run at 00:00<\/p>\n<p># The Nginx logs path<br \/>\nlogs_path=\"\/usr\/local\/webserver\/nginx\/logs\/\"<\/p>\n<p>mkdir -p ${logs_path}$(date -d \"yesterday\" +\"%Y\")\/$(date -d \"yesterday\" +\"%m\")\/<br \/>\nmv ${logs_path}access.log ${logs_path}$(date -d \"yesterday\" +\"%Y\")\/$(date -d \"yesterday\" +\"%m\")\/access_$(date -d \"yesterday\" +\"%Y%m%d\").log<br \/>\nkill -USR1 `cat \/usr\/local\/webserver\/nginx\/nginx.pid`<\/p>\n<p>\u3000\u30002\u3001\u8bbe\u7f6ecrontab\uff0c\u6bcf\u5929\u51cc\u666800:00\u5207\u5272nginx\u8bbf\u95ee\u65e5\u5fd7<\/p>\n<p>crontab -e<\/p>\n<p>\u3000\u3000\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<p>\u5f15\u7528<br \/>\n00 00 * * * \/bin\/bash \/usr\/local\/webserver\/nginx\/sbin\/cut_nginx_log.sh<br \/>\n\u5206\u4eab\u5230\uff1a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001Nginx\u76f8\u5173\u8d44\u6599 \u4e3b\u7ad9\uff1ahttp:\/\/www.nginx.org\/ Nginx\u4e2d\u6587\u7ef4\u57fa:http:\/\/w\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.shuran.cn\/?p=13\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13"}],"version-history":[{"count":1,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":85,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions\/85"}],"wp:attachment":[{"href":"https:\/\/www.shuran.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}