Install Nginx through Ubuntu Compilation

Source: Internet
Author: User
Tags image filter nginx server
The latest stable version of DownloadNginx can be renewed from here

Download Nginx latest stable version

You can download the latest http://nginx.org/en/download.html from here, for example:

Wget http://nginx.org/download/nginx-1.2.2.tar.gz

Apt-get install libpcre3 libpcre3-dev

To support https, refer to the following section:

Apt-get install libssl-dev

Apt-get install openssl

Certificate generation Reference documents:

Http://wiki.nginx.org/NginxHttpSslModule

To support image filter, install GD library

Apt-get install libgd2-xpm-dev

Compile and install

Assume that the downloaded file is in the/usr/src directory.

Tar zxvf nginx-1.2.1.tar.gz

Cd nginx-1.2.1

./Configure -- prefix =/usr/nginx -- with-http_ssl_module -- with-http_image_filter_module
Make
Make install

The file will be installed in the/usr/nginx directory.
Run sudo./nginx in the/usr/nginx/sbin/directory to start nginx.

-- Prefix =/usr/nginx will cause hard coding inside nginx, that is,/usr/nginx will be used as the root directory during program deployment. If the directory is not on your target machine, modify this parameter.

If the directory structure on your target machine is different from that defined in nginx, it will be troublesome. This requirement is special, but I have met it.

Static File Server Construction

Add the following configuration location ~ to the/usr/nginx/conf/nginx. conf file ~ ^/(Images | javascript | js | css | flash | media | static)/{root/opt/resources; expires 1d ;}

Create the/opt/resources Directory and copy the css, images, and other folders to the following directory. Assume that the imagesdirectory contains a logo.gif image. After nginx is started, you can view the image in the following way: http: // localhost/images/logo.gif

Create System Service

Cd/etc/init. d/
Create an nginx script with the following content:

#! /Bin/sh

### BEGIN INIT INFO
# Provides: nginx
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: nginx
# Description: nginx server
### END INIT INFO

./Lib/lsb/init-functions

PROGRAM =/usr/nginx/sbin/nginx


Test-x $ PROGRAM | exit 0

Case "$1" in
Start)
Log_begin_msg "Starting Nginx server"
/Usr/nginx/sbin/nginx
Log_end_msg 0
;;
Stop)
PID = 'cat/usr/nginx/logs/nginx. Pi'
Log_begin_msg "Stopping Nginx server"
If [! -Z "$ PID"]; then
Kill-15 $ PID
Fi
Log_end_msg 0
;;
Restart)
$0 stop
$0 start
;;
*)
Log_success_msg "Usage: service nginx {start | stop | restart }"
Exit 1
Esac

Exit 0

Then run the following command:
Sudo chmod + x./nginx
Sudo update-rc.d nginx defaults
Now you can use the following command to restart nginx.
Sudo service nginx start
Sudo service nginx stop

For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2

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.