Use Nginx + Apache with high-performance and high-load servers

Source: Internet
Author: User
Tags imagemagick openldap
When talking about the web production environment in Linux, everyone will think of apache as an open-source server software. apache can integrate most applications, such as jsp, php, cgi, and python. However, apache is too bloated and response to static files is too slow, which makes many users feel headaches. nginx, as a new and emerging server software, is positioned far beyond apache in many aspects.

When talking about the web production environment in Linux, we will think of apache, an open-source server software. apache can integrate most applications, such as jsp,Php, Cgi, python, etc., but apache is too bloated and slow response to static files makes many users feel headaches. nginx, as a new server software, goes beyond apache in many aspects and is clearly positioned as a high-performance HTTP and reverse proxy server. therefore, this article focuses on nginx as the frontend and apache as the backend application environment.

Why?NoHow can I use nginx + php (fastcgi) as the production environment?

  1. Php (fastcgi) is not stable enough, and it is prone to 50x errors. It has no advantage in generating relatively complex pages. If it is used for a long time, the php-cgi process will die.
  2. In terms of security, the permissions of multiple users and multiple sites are very serious. php (fastcgi) is often too slow to cope with multiple users and multiple sites, and is not easy to implement.
  3. By integrating other languages, apache can easily perform well. The resource utilization is just right.

Why is nginx used as the frontend and apache used as the backend solution? Nginx is several times or dozens of times different from apache in processing static content. Therefore, it is most appropriate to filter static content in front of nginx.Server Load balancerLow resource consumption, high-performance Forwarding is its characteristic. after nginx filtering, the backend apache processes less content. you only need to handle the dynamic content. with the balance between performance and stability, using nginx + apache will make them show their own value in their respective fields of expertise.

This tutorial usesCentOS 1, 6.0For the environment. Other Linux releases are not tested yet. nginx, php, apache, mysql, pureFtpD is the latest stable version.

Get OS source updates.

Yum upDate
Yum-y install gcc-c ++ bisonPatchUnZipMloCatE flExWget automake autoconf gdCpP gettext readline-devel libjpeg-devel libpng-develFreeType freetype-devel libxml2 libxml2-devel zlib-devel glibc-devel glib2 glib2-develBzip2Bzip2-develNcUrses ncurses-devel curl-devel e2fsprogs e2fsprogs-devel libIdN libidn-devel openldap-clients openldap-servers nss_ldap expat-devel libtool-ltdl-devel

If apache is installed by default, uninstall it first. Run:

Yum removeHttpd

Download the latest stable version of the program source code packageThe following are the source code packages downloaded from the official website or sourceforge.

Cd/Usr/local/src
Wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.45.tar.gz/from/http://mysql.he.net/
Wget http://www.apache.org/dist/httpd/httpd-2.2.15.tar.gz
Wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
Wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
Wget http://sourceforge.net/projects/McRypt/FileS/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2/download
Wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download
Wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2/download
Wget http://www.php.net/get/php-5.2.13.tar.gz/from/this/mirror
Wget http://www.lancs.ac.uk /~ Steveb/patches/php-mail-header-patch/php5-mail-header.patch
Wget http://pecl.php.net/get/memcache-2.2.5.tgz
Wget http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6.tar.bz2
Wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
Wget http://pecl.php.net/get/imagick-2.3.0.tgz
Wget http: // download.SuHosin.org/suhosin-0.9.29.tgz
Wget http://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86.tar.gz
Wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
Wget http://monkey.org /~ Provos/libevent-1.4.13-stable.tar.gz
Wget http: // memcachEd.Googlecode.com/files/memcached-1.4.4.tar.gz
Wget http://sourceforge.net/projects/pcre/files/pcre/8.01/pcre-8.01.tar.gz/download
Wget http://nginx.org/download/nginx-0.7.65.tar.gz
Wget http://download.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.28.tar.gz

1. Install Mysql. Install the latest stable version 5.1.45 without using the latest development version.

GroupaDdMysql-g 27
UseraddMysql-u 27-g 27-c "MySQL Server"-d/var/lib/mysql-m
Cd/usr/local/src
Tar-zxf mysql-5.1.45.tar.gz
Cd mysql-5.1.45
./Configure -- prefix =/usr/local/mysql -- locaLsTatedir =/var/lib/mysql -- with-unix-socket-path =/var/lib/mysql. sock -- with-mysqld-user = mysql --Enable-Cycler -- enable-thread-safe-client -- with-exTrA-charSetS = all -- with-big-tables -- with-readline -- with-ssl -- with-embedded-server -- enable-local-infile -- with-plugins = partition, innodb_plugin, myisam, myisammrg
Make & make install
Cd ../

Cp/usr/local/mysql/share/mysql/my-medium.cnf/etc/my. cnf
/Usr/local/mysql/bin/mysql_install_db -- user = mysql
Chown-R mysql. mysql/var/lib/mysql
Chgrp-R mysql/usr/local/mysql /.
Cp/usr/local/mysql/share/mysql. server/etc/init. d/mysql
ChmodU + x/etc/init. d/mysql
Chkconfig-- Level 345 mysql on
Echo "/usr/local/mysql/lib/mysql">/etc/ld. so. conf
Echo "/usr/local/lib">/etc/ld. so. conf
Ldconfig
Ln-S/usr/local/mysql/lib/mysql/usr/lib/mysql
Ln-s/usr/local/mysql/include/mysql/usr/include/mysql
Ln-s/usr/local/mysql/bin/mysql_config/usr/bin/mysql_config
Service mysql start
/Usr/local/mysql/bin/mysqladmin-u root password root
Service mysql restart
Service mysql stop

2. Compile and install apache (httpd). The execution user of apache is nobody.

Cd/usr/local/src
Tar-zxf httpd-2.2.15.tar.gz
Cd httpd-2.2.15
./Configure -- prefix =/usr/local/apache -- enable-headers -- enable-mime-magic -- enable-proxy -- enable-reWrite-- Enable-ssl -- enable-suexec -- disable-userdir -- with-encoded-apr -- with-mpm = prefork -- with-ssl =/usr -- with-suexec-caller = nobody -- with-suexec-docroot =/-- with-suexec-gidmin = 100 -- with-suexec-logfile =/usr/local/apache/logs/suexec_log -- with-suexec-uidmin = 100 -- with-suexec-userdir = public_html
Make
Make install
Mkdir/Usr/local/apache/domlogs
Cp/usr/local/apache/bin/Apachectl/Etc/init. d/httpd

1. edit/etc/init. d/httpd, In the first line #! Add:

# Startup script for the Apache Web Server
#
# Chkconfig:-85 15
# Description: Apache is a World Wide Web server. It is uSedTo serve \
# HTML files and CGI.
# Processname: httpd
# PiDfIle:/usr/local/apache/logs/httpd. pid
# Config:/usr/local/apache/conf/httpd. conf

Ulimit-N 1024
Ulimit-n 4096
Ulimit-n 8192
Ulimit-n 16384
Ulimit-n 32768

Save and exit.

2. Configure the apache configuration parameter file httpd. conf in the/usr/local/apache/conf/directory.

Cd/usr/local/apache/conf/
MvHttpd. conf httpd. conf. bak
Mkdir vhosts
Vi httpd. conf

Enter the following content:

PidFile logs/httpd.pidLockFile logs/accept.lockServerRoot "/usr/local/apache"Listen 0.0.0.0:81User nobodyGroup nobodyServerAdmin admin@evlit.comServerName host.evlit.comTimeout 300KeepAlive OffMaxKeepAliveRequests 100KeepAliveTimeout 5UseCanonicalName OffAccessFileName .htaccessTraceEnable OffServerTokens ProductOnlyFileETag NoneServerSignature OffHostnameLookups Off# LoadModule perl_module modules/mod_perl.soDocumentRoot "/usr/local/apache/htdocs"
 
   Options ExecCGI FollowSymLinks Includes IncludesNOEXEC -Indexes -MultiViews SymLinksIfOwnerMatch Order allow,deny Allow from all AllowOverride All
 
 
   Options Includes -Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all
 DefaultType text/plainRewriteEngine onAddType text/html .shtmlAddHandler cgi-script .cgi .pl .plx .ppl .perlAddHandler server-parsed .shtml
 
      TypesConfig conf/mime.types    AddType application/perl .pl .plx .ppl .perl    AddType application/x-img .img    AddType application/x-httpd-php .php .php3 .php4 .php5 .php6    AddType application/x-httpd-php-source .phps    AddType application/cgi .cgi    AddType text/x-sql .sql    AddType text/x-log .log    AddType text/x-config .cnf conf    AddType text/x-registry .reg    AddType application/x-
  compress .Z    AddType application/x-
  gzip .gz .tgz    AddType text/html .shtml    AddType application/x-tar .tgz    AddType application/rar .rar    AddType application/x-compressed .rar    AddType application/x-rar .rar    AddType application/x-rar-compressed .rar    AddType text/vnd.wap.wml .wml    AddType image/vnd.wap.wbmp .wbmp    AddType text/vnd.wap.wmlscript .wmls    AddType application/vnd.wap.wmlc .wmlc    AddType application/vnd.wap.wmlscriptc .wmlsc
 
 
   DirectoryIndex index.html index.htm index.shtml index.php index.perl index.pl index.cgi
 
 
   Order allow,deny Deny from all Satisfy All
 
 
   Order allow,deny Deny from all Satisfy All
 ErrorLog "logs/error_log"LogLevel warn
 
   LogFo
  rmat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common 
  
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio 
   CustomLog "logs/access_log" common
 
 
  alias_module> ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
 
 
   AllowOverride None Options None Order allow,deny Allow from all
 
 
   StartServers          3 MinSpareServers       3 MaxSpareServers       5 MaxClients          150 MaxRequestsPerChild   1024
 
 
  
   Header set Cache-Control "max-age=3600, must-r
   evalidate"
  
 ReadmeName README.htmlHeaderName HEADER.htmlIndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,tInclude conf/extra/httpd-languages.conf
 
  status> SetHandler server-status Order deny,allow Deny from all Allow from 127.0.0.1
 ExtendedStatus On
 
   SetHandler server-info Order deny,allow Deny from all Allow from 127.0.0.1
 
 
  Listen 0.0.0.0:443AddType application/x-x509-ca-cert .crtAddType application/x-pkcs7-crl .crlSSLCipherSuite ALL:!ADH:+HIGH:+MEDIUM:-LOW:-SSLv2:-EXPSSLPassPhraseDialog  builtinSSLSessionCache         dbm:/usr/local/apache/logs/ssl_scacheSSLSessionCacheTimeout  300SSLMutex  file:/usr/local/apache/logs/ssl_mutexSSLRandomSeed startup builtinSSLRandomSeed connect builtin
 #VhostsNameVirtualHost 127.0.0.1:81NameVirtualHost *
 
   ServerName host.evlit.com DocumentRoot /var/www/html ServerAdmin admin@evlit.com
 Include conf/vhosts/*

Change 127.0.0.1 in the preceding VM configuration to your local public IP address.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.