Compile and install under CentOS High performance Nginx

Source: Internet
Author: User
Tags openssl library what parameter

Install Nginx Dependency Package: Pcre, Pcre-devel

The compiler actually needs a dependency package that is pcre-devel, which can be executed by yum install Pcre-devel. However, the installation of this package is very simple, just let us take it to practice practiced hand, familiar with the general process of Linux compilation and installation software.

[tips] Linux from the source code to compile the installation software is generally three steps: Configuration, compilation, installation. The exact point is to execute three commands: Configure, make, make install. Not much theory, practical operation will understand.

Create subdirectories under the build directory Pcre

[[email protected] build]$ mkdir pcre[[email protected] build]$ CD Pcre

Use the Wget tool to download the Pcre package from pcre, download the link as ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.zip, unzip it to the Pcre directory

[Email protected] build]$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.zip

It can be downloaded in a few seconds. (if prompted Bash:wget:command not found that is you have not installed wget, switch to root user,yum install wget-y installed)

[Email protected] pcre]$ Lspcre-8.21.zip

Look, just download the Pcre source package, this is a zip package, using the unzip command to decompress the

[[email protected] pcre]$ unzip Pcre-8.21.zip[[email protected] pcre]$ ll total dosage 1680drwxr-xr-x 6 Feng Feng 4096 December 12 201 1 pcre-8.21-rw-rw-r--1 Feng Feng 1709377 June 13:50 pcre-8.21.zip[[email protected] pcre]$ CD pcre-8.21

Go inside and see what's in it. Special attention to configure

File

[[email protected] pcre-8.21]$ ll total dosage 3716-rwxr-xr-x 1 Feng Feng 6961 October 5 132html-rw-r--r--1 Feng Feng 338277 12  Monthly Aclocal.m4 .....  (slightly)-rwxr-xr-x 1 Feng Feng 595700 December configure ..... (slightly)-rw-r--r--1 Feng Feng 3460 August 2 ucp.h

This configure file, is the "source installation three steps" of the first step of the Configure, it will check whether your system has compiled pcre necessary software packages, configure the environment for compiling Pcre, for the second step. If some software is missing, it will give you a hint.

[Tips] In addition, note that this directory also has several file readme, insall,licence, they are ordinary text files for the user to read, respectively, is the Readme file, installation instructions, licensing agreement. Usually Linux/unix the world's source code package has these files (sometimes the author will install and into the Readme), suggest reading, especially the Readme and install.

Perform the first step configure

[Email protected] pcre-8.21]$./configure

Note that the Configure command is preceded by a./, because we are going to execute the Configure file in the current directory.

Several errors that may occur during the configure process, and why:

    • 1) ./configure:error:c compiler gcc is not found reason: you do not have GCC installed, so you may not have installed the following packages, please install
      Yum install gcc gcc-c++ autoconf make
    • 2) Makefile: Insufficient Authority reason: the current user does not have permission to read and write Nginx source directory, please switch to root run the following command, the role is to set the current directory of all the file owners are the normal user we are using.
      [Email protected] nginx-1.2.1]# chown-r Feng:feng/[[email protected] nginx-1.2.1]# exit

      Then exit exits to the normal user state. Chown after the Feng:feng is the user name of the ordinary account used, and its user group name.

Start compiling, this step is very simple, run make can, it may take a few minutes, you can do something else, such as get up and move on.

[[email protected] pcre-8.21]$ make

If you see the following message:make[1]: Leaving directory '/home/feng/build/pcre/pcre-8.21 '
If the compilation is complete, start the installation. Installation is simple, use the root user right, run make install . So Su, follow the prompts to enter the root password, switch to root identity

[email protected] pcre-8.21]$ su
[[email protected] pcre-8.21]# make install

The message should be make[1]: Leaving directory '/home/feng/build/pcre/pcre-8.21 '

So the pcre is ready to be installed. Then exit returns to the normal user state.

Compile and install Nginx

The next step is to really install nginx, the process is similar, but we need to configure several parameter options.

To the Nginx official online http://nginx.org/en/download.html find the latest stable version of the download link, when writing this article, 2012-06-30 the latest version of the nginx-1.2.1 download link for HTTP// nginx.org/download/nginx-1.2.1.tar.gz use wget to download it to the VPS.

[Email protected] build]$ wget http://nginx.org/download/nginx-1.2.1.tar.gz

It can be downloaded in a few seconds. (if prompted Bash:wget:command not found that is you have not installed wget, switch to root user,yum install wget-y installed)

Unzip, and then move the package to the source directory for a rainy-out.

[[email protected] build]$ ll total dosage 708-rw-r--r--1 root root 718161 June 5 14:10 nginx-1.2.1.tar.gz[[email protected] build] $ tar XF nginx-1.2.1.tar.gz [[email protected] build]$ ll total dosage 712drwxr-xr-x 8 1001 1001 4096 June 5 14:02 nginx-1.2.1-rw- r--r--1 root root 718161 June 5 14:10 nginx-1.2.1.tar.gz[[email protected] build]$ mv nginx-1.2.1.tar.gz. /source/

[Tips] file name is very long, typing is too tired? Try the TAB key, such as first playing the MV Ngi and then pressing the TAB key once, not responding, then pressing once to see what changes; then continue to hit a period and press TAB again. I'm sure you can think of something.

Enter the Nginx source directory, browse the files inside

[[Email protected] build]$ CD Nginx-1.2.1/[[email protected] nginx-1.2.1]$ ll total dosage 560drwxr-xr-x 6 1001 1001 4096 June 30 1  1:39 auto-rw-r--r--1 1001 1001 207988 June 5 14:02 changes-rw-r--r--1 1001 1001 317085 June 5 14:02 changes.rudrwxr-xr-x  2 1001 1001 4096 June 11:39 conf-rwxr-xr-x 1 1001 1001 2345 January 15:07 configuredrwxr-xr-x 3 1001 1001 4096 June 11:39 contribdrwxr-xr-x 2 1001 1001 4096 June 11:39 html-rw-r--r--1 1001 1001 1365 January 15:07 LICENSEDRWXR-XR  -X 2 1001 1001 4096 June 11:39 man-rw-r--r--1 1001 1001 49 October readmedrwxr-xr-x 8 1001 1001 4096 June 30 11:39 SRC

Run Configure, this directory is the file, the above marked red Plus, the directory is the configuration Nginx compiler environment, run the following command, the parameters are longer, you can directly copy the posts.

[Email protected] nginx-1.2.1]$ /configure--prefix=/usr/local/nginx--sbin-path=/usr/local/sbin/nginx-- conf-path=/usr/local/conf/nginx/nginx.conf--error-log-path=/var/log/nginx/error.log--pid-path=/var/run/ Nginx.pid--lock-path=/var/run/nginx.lock --with-http_stub_status_module--with-http_gzip_static_module-- With-http_sub_module--with-http_flv_module--with-http_mp4_module--with-http_random_index_module--with-cpu-opt= Pentium4

Note that the configure command should be taken./, the above is marked with red display. What does that mean? [note] If you just want to compile a Web environment and don't want to learn the general method of compiling a Linux program, that part can be skipped without looking.

Rearrange the parameters of the next version, one line of parameters, a simple comment

--prefix=/usr/local/nginx #编译后安装到目录/usr/local/nginx--sbin-path=/usr/local/sbin/nginx #--conf-path=/usr/local/ conf/nginx/nginx.conf #主配置文件路径--error-log-path=/var/log/nginx/error.log #错误日志目录--pid-path=/var/run/nginx.pid # When the Nginx program is enabled, its process number is automatically written to the file--lock-path=/var/run/nginx.lock #lock文件路径--with-http_stub_status_module # View Nginx running status--with-http_gzip_static_module #gzip压缩支持--with-http_sub_module through the web     #加入ngx_http_sub_ Module Modules--with-http_flv_module     #加入flv模块--with-http_mp4_module #mp4模块--with-http_random_index_module #http_ Random_index_module module--WITH-CPU-OPT=PENTIUM4 #针对intel CPU optimization

--with-xxxx_module of those modules if you're sure

No need, then you can not join. So that's it. Specifying parameters

./configure--prefix=/usr/local/nginx--sbin-path=/usr/local/sbin/nginx--conf-path=/usr/local/conf/nginx/ nginx.conf--error-log-path=/var/log/nginx/error.log--pid-path=/var/run/nginx.pid--lock-path=/var/run/ Nginx.lock --with-http_stub_status_module--with-http_gzip_static_module

Only two more useful modules are available. In fact, these parameters are not specified, it is also possible, so that the default configuration by Nginx is compiled. If you want to see what parameter options are available for Ngix's configure, you can run it ./configure--help , there's not much to tell.

If error:./configure:error:the HTTP Rewrite module requires the PCRE library.
You can either disable the module by using--without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
Statically from the source with Nginx by using--with-pcre=<path> option.

This is because the Pcre package is not found, please check if the PCRE package is installed correctly:

No surprises, you should be able to see this report message:

Configuration Summary + using System PCRE Library + OpenSSL Library is not used + md5:using system Crypto Library + s Ha1:using System Crypto Library + using System zlib library nginx Path prefix: "/usr/local/nginx" nginx binary file: " /usr/local/sbin/nginx "Nginx configuration prefix:"/usr/local/conf/nginx "Nginx configuration file:"/usr/local/conf/ nginx/nginx.conf "nginx pid file:"/var/run/nginx.pid "nginx error log file:"/var/log/nginx/error.log "Nginx http acce  SS log File: "/usr/local/nginx/logs/access.log" nginx HTTP client request body Temporary files: "Client_body_temp" Nginx HTTP Proxy temporary files: "proxy_temp" Nginx http fastcgi temporary files: "fastcgi_temp" Nginx http Uwsgi Temporary Files: "uwsgi_temp" Nginx http scgi temporary files: "Scgi_temp"

Some of the software's configure are completed with a similar configuration report for us to check if the configuration options are correct. If there is an incorrect place, or if you want to change it again, run the Configure--xx--yyy again.

Confirm error, start compiling

[[email protected] nginx-1.2.1]$ make

Start compiling, very fast, may compile in a minute, the final message is roughly like:make[1]: Leaving directory '/home/feng/build/nginx-1.2.1 '

Next, you should know, switch to root identity, make install installation.

Nginx Run Test

The following actions are to be operated under root.

Let's test if Nginx is working properly. Because we have nginx binary execution file configuration installed in/usr/local/sbin/nginx (front configure parameter--sbin-path=/usr/local/sbin/nginx), directory/usr/local/ sbin/default in the PATH environment variable of Linux, so we can omit the path to execute it:

[Email protected] nginx-1.2.1]# Nginx

It will not have any information to display. Open the browser, through the IP address to access your Nginx site, if you see such a large line of black words, it proves that Nginx has been working:

Welcome to nginx!

It looks shabby, just because it doesn't make a nice page. Let's simply configure its run configuration. We configure the parameter --conf-path=/usr/local/conf/nginx/nginx.conf This is its configuration file. Let's go and see.

[Email protected] nginx-1.2.1]# cd/usr/local/conf/nginx/[[email protected] nginx]# lsfastcgi.conf Fastcgi_param S.default mime.types nginx.conf.default uwsgi_paramsfastcgi.conf.default koi-utf mime.types.d Efault scgi_params uwsgi_params.defaultfastcgi_params Koi-win nginx.conf Scgi_pa Rams.default Win-utf

If there is no nginx.conf, but there is a nginx.conf.default, we use it to copy a copy of nginx.conf (the previous version is not nginx.conf by default)

Using your familiar editor to open it, it is recommended to use VIM, if not, then use the Nano, the function is simple, but a look will be used:nano nginx.conf

Find the following section, about 35 lines,

server {Listen defaultroot/var/www/html/default;        #charset Koi8-r;        #access_log Logs/host.access.log Main;            Location/{# root HTML;        Index index.html index.htm; }................}

As the red bold Display section, make three changes:

    • Listen Gen Y Insert "space default"
    • Add a row of root/var/www/html/default inside;
    • Comment out root html; Line

Above the server{....} is a defined virtual host, and the line we just joined is the web directory that defines the bogus host. The default of listen line is to indicate this server{...} node is the default false host (default site)

Do nginx-t test the Nginx configuration file just now for syntax errors:

[Email protected] nginx]# nginx-tnginx:the configuration file/usr/local/conf/nginx/nginx.conf syntax is OKNGINX:CONFI Guration file/usr/local/conf/nginx/nginx.conf Test is successful

show no errors, detect pass. If this is not the case, please go back and carefully check if your profile is wrong, and notice that there is a semicolon at the end of the line.

We created this directory on the hard disk:

[Email protected] nginx]# mkdir-p/var/www/html/default

Write an HTML file index.html to the /var/www/html/default directory, use your familiar editor, write whatever content you want, and how to format it.

Then let Nginx reload the configuration file to see how the HTML page you just authored is performing.

Common Error FAQs

1) If you normally see Welcome to nginx! when you visit, please return to the check, focusing on these points:

    • Make sure you have the index.html file you created in the/var/www/html/default directory?
    • Check the file permissions, do other users have Read permissions? If you do not understand Linux file permissions, perform chmod 755/var/www/html/default/index.html
    • Check the nginx.conf configuration file, there is only one server{...} node, and if there is listendefault in the node; One line, note that there should be default .
    • Check the above server{...} Whether there is root/var/www/html/default in the node; Line, note that the path is spelled correctly.
    • Check the # root HTML in the node of location/{...}. One line, whether it was commented out.

2) If you see a hint like 404 Not Found or "Can't find this page":

    • Check the above location/{...} node for this line index index.html index.htm;

3) If you visit, the error "Server not found" and "Cannot connect to server" is displayed:

    • Run check nginx process running, run PS aux |grep nginx Command, normal situation has the following three:
      Nginx:master process Nginx
      Nginx:worker process
      grep nginx
      If only the third, please run nginx re-enable Nginx, if there is an error, please follow the instructions to check. This is generally a syntax error for the configuration file.
    • Please run nginx-t to check the configuration file for syntax errors.

[Tips] the # root HTML in the location/{...} node; One line, not commented out can also: please put the index.html you created in the /var/www/html/default/html directory.

At this point, our nginx can also work properly.

Compile and install under CentOS High performance Nginx

Related Article

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.