[Ngnix learning] 001_ubuntu11.10 source code compilation nginx

Source: Internet
Author: User
Tags install openssl openssl library nginx server

I. Preface
At the end of the rabbit's day, the Ubuntu system installed in wubi was uninstalled because the capacity was insufficient and the system was running very slowly, so the system was unmounted, reorganized, and integrated into an independent dual system. However, after I installed the system, it would be time to get off work, so the first thing that comes back this year is, of course, re-configuring an environment. Since I was in contact with PHP, I have always used Apache servers. This time I used nginx. By the way, I tried the source code installation method, although it was troublesome.

2. Preparations
Local sub-Environment: 64-bit Ubuntu 11.10
1 download nginx: http://nginx.org/en/download.html
# I use version 1.1.13.
2. Download PCRE: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
# I use version 8.20.

Iii. installation and configuration process
3.1 install PCRE
Because I used the source code to install nginx, Google installed it to better use regular expressions in nginx.

# Tar zxvf pcre-8.20.tar.gz
# Cd pcre-8.20
#./Configure-Prefix =/usr/local/pcre-8.20
# Install to/usr/local/pcre-8.20
# Make
# Sudo make install

3.2 install nginx

# tar zxvf nginx-1.1.13.tar.gz
# cd nginx-1.1.13
# ./configure –prefix=/usr/local/nginx –pid-path=/var/run/nginx.pid--with-http_stub_status_module –with-http_ssl_module

At this time, an error occurs:
PCRE Library missing
. /Configure: error: the HTTP rewrite module requires the pcrelibrary. 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.
However, if I have installed PCRE in the source code, it is still an error. I cannot explain it. Do you need to specify-winth-PCRE?
So I configured the following:

# ./configure –prefix=/usr/local/nginx –pid-path=/var/run/nginx.pid --with-http_stub_status_module –with-http_ssl_module –with-pcre=/usr/local/pcre-8.20/lib

However, it is still incorrect, so I plan to check the-with-PCRE option:

# ./configure –help

The results are as follows:

-- With-PCRE force PCRE Library usage
-- With-PCRE = dir set path to PCRE Library sources # source code path to PCRE

Need to point to source code ?? Try again as follows:

# ./configure –prefix=/usr/local/nginx –pid-path=/var/run/nginx.pid --with-http_stub_status_module –with-http_ssl_module –with-pcre=/home/xiaoxiao/Download/pcre-8.20

It is found that the compilation can be passed. Will it re-compile the PCRE? Unknown ~
However, there are several errors:

Error 1: The OpenSSL library is missing.
. /Configure: 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.
Solution: Install OpenSSL:

# sudo apt-get install openssl

Error 2: the zlib library is missing
. /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.
Solution: Install libssl-Dev

# sudo apt-get install libssl-dev

After the above:

# ./configure –prefix=/usr/local/nginx –pid-path=/var/run/nginx.pid --with-http_stub_status_module –with-http_ssl_module –with-pcre=/home/xiaoxiao/Download/pcre-8.20
# make
# sudo make install

After that, you need to set the/usr/local/nginx/logs directory to writable, which contains a series of log files:

# Sudo chmod 777 R/usr/local/nginx/logs
# Nginx # Start nginx
# Curl-I http: // localhost

The result is as follows:

HTTP/1.1 200 OK
Server: nginx/1.1.13
Date: Mon, 30 Jan 2012 09:44:28 GMT
Content-Type: text/html
Content-Length: 151
Last-Modified: Mon, 30 Jan 2012 08:57:55 GMT
Connection: keep-alive
Accept-Ranges: bytes
<title>Welcome to nginx!</title>
<body bgcolor="white" text="black">
<center></body>

You can also open the webpage and run localhost to see "Welcome to nginx !" Words

3.3 Precautions
When installing the source code, you need to install the compiling environment. Under GCC Ubuntu, you can directly install apt-get:

# sudo apt-get install libtool
# sudo apt-get install gcc-c++

The following error occurs when installing GCC:
An error occurred while installing gcc-C ++.

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Couldn't find package gcc-c

Follow these steps to install the SDK again:

# sudo apt-get install build-essential
# sudo apt-get update
# sudo apt-get upgrade
# sudo apt-get install gcc-c++

 

4. Configure nginx to serve the system
1. Configure to System Path

# sudo vim /etc/bash.bashrc

Add at the end of the file:

if [ -d "/usr/local/nginx/sbin" ]; then
PATH="$PATH:/usr/local/nginx/sbin"
fi

2. Add the startup management file and enable the nginx Web server to run automatically when Ubuntu is started.

# wget http://nginx-init-ubuntu.googlecode.com/files/nginx-init-ubuntu_v2.0.0-RC2.tar.bz2
# tar jxvf nginx-init-ubuntu_v2.0.0-RC2.tar.bz2
# sudo vim nginx

Change the nginx installation path and nginx configuration file path

PATH=/usr/local/nginx/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/nginx/sbin/nginx
PS="nginx"                
PIDNAME="nginx"            
PIDFILE=$PIDNAME.pid          
PIDSPATH=/var/run            
DESCRIPTION="Nginx Server..."    
RUNAS=root               
SCRIPT_OK=0              
SCRIPT_ERROR=1            
TRUE=1
FALSE=0

lockfile=/var/lock/subsys/nginx
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

Put the file in/usr/local/nginx and set it to executable, and add soft connections to/etc/init. d for execution:

# Sudo MV nginx/usr/local/nginx
# Chmod + x/usr/local/nginx
# Sudo ln-S/usr/local/nginx/etc/init. d/nginx # Add soft connection to the/etc/init. d directory
# Update-rc.d-F nginx defaults

Command to start and stop/restart:

#sudo /etc/init.d/nginx start   
#sudo /etc/init.d/nginx stop
#sudo /etc/init.d/nginx restart

Complete.

From: http://www.189works.com/article-39997-1.html

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.