Ubuntu installs Nginx from official sources
CD ~
wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
sudo nano/etc/apt/ Sources.list # Add the following two sentences to
Deb http://nginx.org/packages/ubuntu/precise nginx
deb-src http://nginx.org/ Packages/ubuntu/precise nginx
sudo apt-get update
sudo apt-get install Nginx
Ubuntu installs Nginx from the PPA source:
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install Nginx
Ubuntu installs Nginx from a regular source:
sudo apt-get install Nginx
Compile and install Nginx
wget http://nginx.org/packages/mainline/ubuntu/pool/nginx/n/nginx/nginx_1.5.7-1~precise_i386.deb
wget http:/ /nginx.org/download/nginx-1.5.7.tar.gz
tar xzf nginx-1.5.7.tar.gz
CD nginx-1.5.7
(Note: Nginx1.5.7 is a mainline version and not a stable version)
To facilitate development and management, I created a new PNG directory under the root directory, and the directory owner is set to the current user, and Nginx is compiled under/png/nginx/1.5.7:
sudo mkdir/png
sudo chown eechen:eechen/png
Run user I defined as png:png, so I need to create a new user like this:
sudo addgroup png--system
sudo adduser png--system--disabled-login--ingroup PNG--no-create-home--home/nonexiste NT--gecos "PNG user"--shell/bin/false
(The new user's command can refer to the preinstallation script Debian/preinst in the official Deb pack)
The compilation parameters refer to the Nginx's official Deb package (nginx-v visible).
--prefix=/png/nginx/1.5.7 \--sbin-path=/png/nginx/1.5.7/sbin/nginx \--conf-path=/png/nginx/1.5.7/conf/nginx.conf \--error-log-path=/png/nginx/1.5.7/var/log/error.log \--http-log-path=/png/nginx/1.5.7/var/log/access.log \-- Pid-path=/png/nginx/1.5.7/var/run/nginx.pid \--lock-path=/png/nginx/1.5.7/var/run/nginx.lock \-- Http-client-body-temp-path=/png/nginx/1.5.7/var/cache/client_temp \--http-proxy-temp-path=/png/nginx/1.5.7/var/ cache/proxy_temp \--http-fastcgi-temp-path=/png/nginx/1.5.7/var/cache/fastcgi_temp \--http-uwsgi-temp-path=/png/ nginx/1.5.7/var/cache/uwsgi_temp \--http-scgi-temp-path=/png/nginx/1.5.7/var/cache/scgi_temp \--user=png \--group =png \--with-http_ssl_module \--with-http_realip_module \--with-http_addition_module \--with-http_sub_module \-- With-http_dav_module \--with-http_flv_module \--with-http_mp4_module \--with-http_gunzip_module \--with-http_gzip_ Static_module \--with-http_random_index_module \--with-http_secure_link_module \--with-http_stUb_status_module \--with-mail \--with-mail_ssl_module \--with-file-aio \--with-ipv6
Note: This step is to install the dependent packages by mistake, and it is time for apt to kick back, for example, my system installs these packages:
build-essential \
autoconf \
libtool \
libxml2 \
libxml2-dev \
OpenSSL
\ Libcurl4-openssl-dev \
libbz2-1.0 \
libbz2-dev \
libjpeg-dev \
libpng12-dev \
libfreetype6 \
libfreetype6-dev \
libldap-2.4-2 \
libldap2-dev \
libmcrypt4 \
libmcrypt-dev \
Libmysqlclient-dev \
libxslt1.1 \
libxslt1-dev \
libxt-dev \
Libpcre3-dev
After installing these packages, the next time you compile the new version of the Nginx will not have to install, and basically meet the need to compile PHP configure.
OK, configure can be compiled and installed after successful:
Time make && make install
Time is primarily used to see how time-consuming this compilation is.
After compiling, you can look at this guy's head:
Du-sh/png/nginx/1.5.7/sbin/nginx
5.5m/png/nginx/1.5.7/sbin/nginx
Summary of Environment Simple configuration
reduce the Nginx file size after compilation:
Edit source file NGINX-1.5.7/AUTO/CC/GCC Remove debug information (comment out):
# Debug
# cflags= ' $CFLAGS-G '
The compiled main program has a size of more than 700 k, which is similar to the Nginx's official Deb package program.
In addition, some unwanted modules are removed from the Configure, and the compiled executable file is smaller.
Of course, I need a service script to manage Nginx, and it's also possible to use the service script Etc/init.d/nginx provided in the official Deb package.
I put it in/png/nginx/1.5.7/nginx, and slightly modified a few values (13 to 19 lines) defined at the beginning:
Path=/sbin:/usr/sbin:/bin:/usr/bin
desc=nginx
name=nginx
conffile=/etc/nginx/nginx.conf
DAEMON =/usr/sbin/nginx
pidfile=/var/run/$NAME. PID
scriptname=/etc/init.d/$NAME
changed to
path=/sbin:/usr /sbin:/bin:/usr/bin
desc=nginx
name=nginx
conffile=/png/nginx/1.5.7/conf/nginx.conf
DAEMON =/png/nginx/1.5.7/sbin/nginx
pidfile=/png/nginx/1.5.7/var/run/$NAME. PID
scriptname=/png/nginx/1.5.7/ $NAME
Create a cache directory before starting, or you will be prompted for an error:
Mkdir/png/nginx/1.5.7/var/cache
Start Nginx:
Sudo/png/nginx/1.5.7/nginx start
Test page:
Take a look at the port:
sudo netstat-antp|grep nginx
Check the memory it occupies:
Htop Press F4 Filter Nginx
You can also see similar content with top:
Top-b-n1|head-n7 && top-b-n1|grep nginx
Mainly see res This value, resident memory (resident), excluding the physical memory of the swap space, the unit is Kb,%mem is a reference object with Res.
You can see that nginx two processes take up less than 2M of physical memory, and memory footprint is very small.
In addition, the res in top corresponds to the value of the RSS in PS aux:
PS aux|head-n1 && PS aux|grep nginx
And we can see that the Nginx worker process has only one thread:
Cat/proc/25047/status|grep Threads
25047 of them are nginx worker process PID numbers.
Make the Nginx into system service, boot from start:
sudo ln-s/png/nginx/1.5.7/nginx/etc/init.d/png-nginx
sudo update-rc.d png-nginx defaults #开机自启动
sudo Update-rc.d-f Png-nginx Remove # After you don't want to boot up you can disable
the sudo service Png-nginx reload #这样就可以用service来管理Nginx服务了 such as overloaded configuration
Finally, the Nginx main configuration file is located in/png/nginx/1.5.7/conf/nginx.conf and is configured on demand.