Compile and install nginx in linux and configure the self-starting script

Source: Internet
Author: User

Install nginx on your suse server and record the installation process:

Refer to this article: compile and install Nginx from the source code in Linux:

1.1 prepare the pcre library
Pere is used to enable nginx to support regular expressions. It is only preparation, not installation, to avoid errors in 64-bit systems.

The code is as follows: Copy code

Wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.11.tar.gz

Tar-zxf pcre-8.11.tar.gz

1.3 prepare the zlib library
It is also just preparation, not installation, to avoid errors in 64-bit systems.

The code is as follows: Copy code

Wget http://zlib.net/zlib-1.2.5.tar.gz
Tar-zxf zlib-1.2.5.tar.gz

2.1 Download and create a temporary directory

The code is as follows: Copy code

Wget http://nginx.org/download/nginx-1.5.5.tar.gz // at the company is downloading to local and then rz-by Upload to server
Tar-zxf nginx-1.5.5.tar.gz
Cd nginx-1.5.5
Mkdir-p/var/tmp/nginx

2.2. Compilation and installation

For detailed compilation configuration options, see Nginx compilation parameter parsing

The code is as follows: Copy code

Root64 :~ #. /Configure -- prefix =/usr/local/nginx -- pid-path =/var/run/nginx. pid -- lock-path =/var/lock/nginx. lock -- with-http_dav_module -- with-http_flv_module -- with-http_realip_module -- with-http_gzip_static_module -- with-mail -- with-pcre = .. /pcre-8.11 -- with-zlib = .. /zlib-1.2.5 -- with-debug -- http-client-body-temp-path =/var/tmp/nginx/client -- http-proxy-temp-path =/var/tmp/nginx /proxy -- http-fastcgi-temp-path =/var/tmp/nginx/fastcgi -- http-uwsgi-temp-path =/var/tmp/nginx/uwsgi -- http-scgi -temp-path =/var/tmp/nginx/scgi
Root64 :~ # Make & make install
Root64 :~ # Ln-s/usr/local/nginx/sbin/nginx/usr/sbin/


-- Prefix # nginx installation directory, which is/usr/local/nginx by default
-- Pid-path # pid location, which is in the logs directory by default
-- Lock-path # The location of the lock component. The default value is in the logs directory.
-- With-http_ssl_module # enable the http ssl module to support HTTPS requests.
-- With-http_dav_module # enable the WebDAV extension action module to specify permissions for files and directories
-- With-http_flv_module # supports drag playback of FLV files
-- With-http_realip_module # supports displaying real source IP addresses
-- With-http_gzip_static_module # pre-compressed file pre-pass check to prevent files from being repeatedly compressed
-- With-http_stub_status_module # get some nginx running status
-- With-mail # Allow POP3/IMAP4/SMTP proxy module
-- With-mail_ssl_module # Allow POP3/IMAP/SMTP to use SSL/TLS
-- With-pcre = ../pcre-8.11 # note that the pcre path is not installed
-- With-zlib = ../zlib-1.2.5 # note that the zlib path is not installed
-- With-debug # allow debugging logs
-- Http-client-body-temp-path # path of the temporary file requested by the client
-- Http-proxy-temp-path # set the temporary file path of http proxy
-- Http-fastcgi-temp-path # set the http fastcgi temporary file path
-- Http-uwsgi-temp-path =/var/tmp/nginx/uwsgi # set the uwsgi temporary file path
-- Http-scgi-temp-path =/var/tmp/nginx/scgi # set the scgi temporary file path

2.3 start nginx script at startup

The code is as follows: Copy code

/Etc/init. d/nginx
#! /Bin/bash
# Description: Startup script for webserver on CentOS. cp it in/etc/init. d and
# Chkconfig -- add nginx & chkconfig nginx on
# Then you can use server command control nginx
#
# Chkconfig: 2345 08 99
# Description: Starts, stops nginx

Set-e
PATH = $ PATH:/usr/local/nginx/sbin/
DESC = "nginx daemon"
NAME = nginx
DAEMON =/usr/local/nginx/sbin/$ NAME
CONFIGFILE =/usr/local/nginx/conf/nginx. conf
PIDFILE =/var/run/nginx. pid
SCRIPTNAME =/etc/init. d/$ NAME

# Gracefully exit if the package has been removed.
Test-x $ DAEMON | exit 0

D_start (){
$ DAEMON-c $ CONFIGFILE | echo-n "already running"
}

D_stop (){
Kill-QUIT 'cat $ pidfile' | echo-n "not running"
}

D_reload (){
Kill-HUP 'cat $ pidfile' | echo-n "can't reload"
}

Case "$1" in
Start)
Echo-n "Starting $ DESC: $ NAME"
D_start
Echo "."
;;
Stop)
Echo-n "Stopping $ DESC: $ NAME"
D_stop
Echo "."
;;
Reload)
Echo-n "Reloading $ DESC configuration ..."
D_reload
Echo "reloaded ."
;;
Restart)
Echo-n "Restarting $ DESC: $ NAME"
D_stop
Sleep 1
D_start
Echo "."
;;
*)
Echo "Usage: $ SCRIPTNAME {start | stop | restart | force-reload}"> & 2
Exit 3
;;
Esac
Exit 0

Add nginx to the self-starting service and start it:

The code is as follows: Copy code

Chmod 700/etc/init. d/nginx
Chkconfig -- add nginx
Chkconfig -- level 2345 nginx on
/Etc/init. d/nginx start

Configure the daily auto-cut nginx log script:

The code is as follows: Copy code

Vi/usr/local/nginx/sbin/cut_nginx_log.sh

#! /Bin/bash
# This script run at 00:00
# The Nginx logs path
Logs_path = "/usr/local/nginx/logs /"
Logs_bak_path = "/data/logs/nginx /"

Mkdir-p $ {logs_bak_path} $ (date-d "yesterday" + "% Y")/$ (date-d "yesterday" + "% m ")/
Cp $ {logs_path} access. log $ {logs_bak_path} $ (date-d "yesterday" + "% Y")/$ (date-d "yesterday" + "% m ") /access _ $ (date-d "yesterday" + "% Y % m % d "). log
Rm-rf $ {logs_path} *. log
Kill-USR1 'cat/var/run/nginx. Pi'

Installation completed :)

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.