Install and configure nginx in Ubuntu Linux source code

Source: Internet
Author: User
Tags openssl library
1. Prepare the environment

A. First, make sure your system has installed GCC and G ++.

B. Install PCRE

Pcre-8.32 http://sourceforge.net/projects/pcre/files/pcre/ download

A, unzip and install tar-jxvf pcre-8.32.tar.bz2

B, CD pcre-8.32

C,./configure -- prefix =/usr/local/PCRE

D, make

E, make install

2. Install nginx

Download nginx-1.3.15.tar.gz, address: http://nginx.org/en/download.html

A, tar-zxvf nginx-1.3.15.tar.gz

B, CD nginx-1.3.15

C,./configure \
-- Prefix =/usr \
-- Sbin-Path =/usr/local/nginx/sbin \
-- Conf-Path =/etc/nginx. conf \
-- Error-log-Path =/var/log/nginx/error. log \
-- PID-Path =/var/run/nginx. PID \
-- User = nginx \
-- Group = nginx \
With-http_ssl_module \
With-http_flv_module \
With-http_gzip_static_module \
-- Http-log-Path =/var/log/nginx/access. log \
-- Http-client-body-temp-Path =/var/tmp/nginx/client \
-- Http-proxy-temp-Path =/var/tmp/nginx/Proxy \
-- Http-FastCGI-temp-Path =/var/tmp/nginx/fcgi \
With-http_stub_status_module

For more information about configure options, see click open link Configure. We use nginx
By default, if -- prefix =/usr/local/nginx is specified


The/usr/local/nginx directory does not exist.
Sbin directory.

D, make

E, make install


3,
./Problems with configure and make .

A, error: the HTTP cache module requires MD5 Functions
From OpenSSL library. You can either disable the module by using
-- Without-http-Cache option, or install the OpenSSL library into the system,
Or build the OpenSSL library statically from the source with nginx by using
-- With-http_ssl_module -- With-OpenSSL = <path> options.

OpenSSL library needs to be installed

Method:
Https://launchpad.net/ubuntu/precise/+source/openssl/1.0.1-4ubuntu3 download openssl_1.0.1.orig.tar.gz
Unzip the package and install it.



B,./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using -- without-http_gzip_module
Option, or install the zlib library into the system, or build the zlib library
Statically from the source with nginx by using -- With-zlib = <path> option.

Download zlib-1.2.5.tar.gz to install it.


C. Execute make after configure is complete. The following error occurs:

Make-F objs/makefile
Make [1]: Entering directory '/data/source/nginx'
CD/usr/local/UFO/lib/PCRE \
& If [-F makefile]; then make distclean; FI \
& CC = "GCC" cflags = "-O2-fomit-frame-pointer-pipe "\
./Configure -- disable-shared
/Bin/sh:./configure: no such file or directory
Make [1]: *** [/usr/local/services/lib/PCRE/makefile] Error 127
Make [1]: Leaving directory '/data/source/nginx-0.7.61'
Make: *** [Build] Error 2

The solution is found on the Internet:

In configure, specify the PCRE and OpenSSL directories. Use the source code of PCRE and OpenSSL instead of the installed PCRE and OpenSSL ..

The reason is to check the configure -- help | grep PCRE of nginx. You must specify the source code file.

Example: Home/Wang/download/pcre-8.32, home/Wang/download/openssl-1.0.1

The details are as follows:

./Configure -- With-PCRE =/home/Wang/download/pcre-8.32 -- With-OpenSSL =/home/Wang/download/openssl-1.0.1

In this way, make and make install again!

4. Check whether nginx is successfully installed.

A, CD/usr/local/nginx/sbin

B,./nginx-T

Result:
Nginx: the configuration file/usr/local/nginx/CONF/nginx. conf syntax is OK
Nginx: configuration file/usr/local/nginx/CONF/nginx. conf test is successful

Start nginx:

A, CD/usr/local/nginx/sbin

B,./nginx


Or:

Input:/usr/local/nginx/sbin/nginx

Nginx is started with the deamon process by default. Enter the following command:

   curl -i http: // Localhost/
Then, you can check whether nginx is running successfully.
You can also use commands curl -I http:// Localhost/view the Web server version used by our domain name.
If you want to stop nginx after it is started, you can use:

 /usr/local/nginx/sbin/nginx -S stop
Add Environment Variables:
Every execution requiresWriting so much/usr/local/nginx/sbin/nginx is quite troublesome. Now we add the nginx path to the environment variable.
Method 1:
 sudo  vim/Etc/Enviroment
Add the = character string header after path/usr/local/nginx/sbin/nginx:
You can.
Method 2:
Run sudo Vim/etc/profile on the terminal and add
Path =/usr/local/nginx/sbin: $ path
Run the following command after editing: source profile
 

In this way/usr/local/nginx/sbin/nginx
The path is permanently added to the system environment variable.
You can directly perform ngxin in the future. Recommended method 1.


In ubuntu, when the program is started automatically, the command can be placed in the file/etc/init. d/rc. Local.

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.